Cannot post form completed with Javascript

S

SteveYoungTbird

I am starting to experiment with AJAX and have hit a problem which I am
sure must be obvious to an experienced programmer but I cannot seem to
solve it. I have successfully managed to submit a form via Javascript
which is read by a PHP script which then puts the data into an SQL
database. The script is here:

http://steveyoung.myftp.org/secureArea/http_putgettest.html - just
input new names and click the "save" button.

But when I write the data to the form via Javascript I get an MySQL
warning "Duplicate entry '' for key 1" which means that the form is
submitted empty. Also I echo the first item in the form to prove that it
is empty.

http://steveyoung.myftp.org/secureArea/indexMW_Distance20v6.html
http://steveyoung.myftp.org/secureArea/test.js

I would be very grateful for any help with this.

Regards, Steve.
 
E

Erwin Moller

SteveYoungTbird schreef:
I am starting to experiment with AJAX and have hit a problem which I am
sure must be obvious to an experienced programmer but I cannot seem to
solve it. I have successfully managed to submit a form via Javascript
which is read by a PHP script which then puts the data into an SQL
database. The script is here:

http://steveyoung.myftp.org/secureArea/http_putgettest.html - just
input new names and click the "save" button.

But when I write the data to the form via Javascript I get an MySQL
warning "Duplicate entry '' for key 1" which means that the form is
submitted empty. Also I echo the first item in the form to prove that it
is empty.

Hi,

Don't echo the first item, simply put out all you received.
From PHP start with:

echo "<pre>";
printr($_POST);
echo "</pre>";

and you'll see everything that PHP received from the form (assuming you
use Method="POST").



So your form doesn't get its right values set.

I am not going to dive into your code, but do you see any errormessages
in the JavaScript error console?
(If you are on IE, start using Firefox right away. All serious
developers work in FF and test on IE later.)

Regards,
Erwin Moller
Regards, Steve.


--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
 
E

Erwin Moller

Erwin Moller schreef:
echo "<pre>";
printr($_POST);

Typo:
that should be:
print_r($_POST);


--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
 
S

SteveYoungTbird

Erwin said:
Erwin Moller schreef:


Typo:
that should be:
print_r($_POST);
Nice tip, and it helped me isolate the problem which was I was using
"id" instead of "name" and therefore the data wasn't being submitted.

Thanks, Steve.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,689
Members
48,796
Latest member
Greg L.

Latest Threads

Top