Jump to content

form --> MySQL database...


jabbamonkey

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!!!

Link to comment
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.