DROP Posted August 23, 2007 Share Posted August 23, 2007 Hello, I am making an RSVP type form and have the drop down on the form populate from a table that contains only the guest's names. When the guest submits the form, I want to insert the name from the drop down along with their RSVP information (are they attending and how many) into a new table (guests) and delete their name from the first table (invite) so that it no longer appears in the drop down. When I test it, I do not get any errors, but no data is insert or deleted in the the tables in MySQL. Here is my code, anyone have any ideas? <?php //Create Short Variable Names $name = $HTTP_POST_VARS['name']; $attend = $HTTP_POST_VARS['attend']; $number = $HTTP_POST_VARS['number']; if(!$name || !$attend || !$number) { echo 'You have not entered all of the RSVP criteria. Please use the back button to go back and try again.'; exit; } $name = addslashes($name); $attend = addslashes($attend); $number = addslashes($number); @ $db = mysql_pconnect('localhost:/tmp/mysql5.sock', 'xxxxxxx', 'xxxxxxxx'); if (!$db) { echo 'Error: Could not connect to database. Please try again later.'; exit; } mysql_select_db('nickandt_db'); $query = "INSERT INTO guests (name, attending, guests) VALUES ('$name', '$attend', '$number') DELETE FROM invite WHERE name = '$name'"; $result = mysql_query($query); ?> Thanks! -Nick Link to comment https://forums.phpfreaks.com/topic/66411-trouble-inserting-data-from-form-into-table/ Share on other sites More sharing options...
amylou Posted August 24, 2007 Share Posted August 24, 2007 have you tried just inserting the data without deleting it at the same time to see if the insert works? Link to comment https://forums.phpfreaks.com/topic/66411-trouble-inserting-data-from-form-into-table/#findComment-332494 Share on other sites More sharing options...
DROP Posted August 24, 2007 Author Share Posted August 24, 2007 Yeah, I tried that. I also simplified the code a bit to what's below. Now I am getting this error: Parse error: syntax error, unexpected T_VARIABLE in /home/nickandt/www/www/guests/RSVP/rsvp.php on line 180 Line 180 is the line my INSERT statement is on. <?php //Create Short Variable Names $name = $HTTP_POST_VARS['name']; $attend = $HTTP_POST_VARS['attend']; $number = $HTTP_POST_VARS['number']; $dbhost = 'localhost:/tmp/mysql5.sock'; $dbuser = 'xxxxxxxx'; $dbpass = 'xxxxxxxx'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'nickandt_db'; @mysql_select_db($dbname) $sql="INSERT INTO guests (Name, Attending, Number) VALUES ('$name','$attend','$number')"; ?> Link to comment https://forums.phpfreaks.com/topic/66411-trouble-inserting-data-from-form-into-table/#findComment-332520 Share on other sites More sharing options...
amylou Posted August 24, 2007 Share Posted August 24, 2007 in your first post your database names are lower case and in your second they are uppercase. that might be the problem Link to comment https://forums.phpfreaks.com/topic/66411-trouble-inserting-data-from-form-into-table/#findComment-332532 Share on other sites More sharing options...
clearstatcache Posted August 24, 2007 Share Posted August 24, 2007 $dbname = 'nickandt_db'; @mysql_select_db($dbname) <<< the error is for ds line u have no ; $sql="INSERT INTO guests (Name, Attending, Number) VALUES ('$name','$attend','$number')"; Link to comment https://forums.phpfreaks.com/topic/66411-trouble-inserting-data-from-form-into-table/#findComment-332658 Share on other sites More sharing options...
clearstatcache Posted August 24, 2007 Share Posted August 24, 2007 for ds query try to place before the delete $query = "INSERT INTO guests (name, attending, guests) VALUES ('$name', '$attend', '$number'); DELETE FROM invite WHERE name = '$name'"; Link to comment https://forums.phpfreaks.com/topic/66411-trouble-inserting-data-from-form-into-table/#findComment-332660 Share on other sites More sharing options...
teng84 Posted August 25, 2007 Share Posted August 25, 2007 $dbname = 'nickandt_db'; @mysql_select_db($dbname) <<< the error is for ds line u have no ; $sql="INSERT INTO guests (Name, Attending, Number) VALUES ('$name','$attend','$number')"; yes also always add the die if your encountering an error like $sql="INSERT INTO guests (Name, Attending, Number) VALUES ('$name','$attend','$number')"; mysql_query($sql) or die(mysql_error()); ;D Link to comment https://forums.phpfreaks.com/topic/66411-trouble-inserting-data-from-form-into-table/#findComment-333701 Share on other sites More sharing options...
fenway Posted August 27, 2007 Share Posted August 27, 2007 What a mess... it's just a semi-colon; this is nothing to do with mysql. Link to comment https://forums.phpfreaks.com/topic/66411-trouble-inserting-data-from-form-into-table/#findComment-335218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.