Jump to content

Archived

This topic is now archived and is closed to further replies.

jabbamonkey

form --> MySQL database...

Recommended Posts

I have a form that is trying to upload the information into the MySQL satabase. BUT, for some reason the new rows aren\'t being added, and I am not getting any error message.

 

I have similar forms that enter information into other tables just fine, but this one is not working...

 

Can someone tell me the best way to trouble shoot this? As the information isn\'t actually getting submitted in the table, is there some way I can have an error message appear telling me what\'s wrong?

 

Here is the code below....

 

$db = mysql_connect($host, $user, $pass);

mysql_select_db($dbname,$db);



$sql = mysql_query("

  INSERT INTO 

    survey_readerstudy 

    (howold, havepark, fampark, email_address) 

  VALUES 

    (\'$howold\', \'$havepark\', \'$fampark\', \'$email_address\')",$db);

 

Please help!!!

Share this post


Link to post
Share on other sites

you say similiar forms, are you using action=\"PHP_SELF\"? might need to




$data = $_POST[\'data\']; 

 

for all ur variables

Share this post


Link to post
Share on other sites

I have the action going to the confirm page (every form I have, has it\'s own confirm page)

 

action=\"survey_confirm.php\"

 

Not sure what you mean by:

 

$data = $_POST[\'data\'];

 

 

Where would this go, and what would this do?

 

Jabbamonkey

Share this post


Link to post
Share on other sites

the $data = $_POST[\'data\']; that that guy is referring to means that the you might not have register_globals turned on in his/her php.ini file. If you don\'t have it on, it would tell you that it couldn\'t find the variable that you are referring to., if it doesn\'t do this, don\'t worry about it, if it does, then you need to either turn register globals on (if you can) or make sure every variable you are trying to turn on is initialized first, as in:

 

[php:1:135977b415]<?php

$howold=$_POST[\'howold\'];

$havepark=$_POST[\'havepark\'];

?>[/php:1:135977b415]

etc.

 

 

as for the original problem, try and change your code to:

 

[php:1:135977b415]<?php

$db = mysql_connect($host, $user, $pass);

mysql_select_db($dbname,$db);

 

$inserted = mysql_query(\"INSERT INTO `survey_readerstudy` (`howold`,`havepark`,`fampark`,`email_address`) VALUES (\'$howold\', \'$havepark\', \'$fampark\', \'$email_address\')\",$db) or die (mysql_error());

 

?>[/php:1:135977b415]

 

that way if any error results in stopping the db from inserting the record, it will stop the page right then and there and output the error message.

 

if you want your page to continue only if it inserts, do this:

 

[php:1:135977b415]<?php

if ($inserted) { // this is the query variable of your insert into query

// insert your successful code

} elseif (!$inserted) {

// output your error message here

}

?>[/php:1:135977b415]

 

hope this helps

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.