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 Quote Link to comment 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? Quote Link to comment 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')"; ?> Quote Link to comment 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 Quote Link to comment 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')"; Quote Link to comment 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'"; Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.