Jump to content

Trouble Inserting Data from Form into Table


DROP

Recommended Posts

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
Share on other sites

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
Share on other sites

 

$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 ;D

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.