tqla Posted July 2, 2007 Share Posted July 2, 2007 All of the variables are registered with the session and I see them when I do a test. Knowing that I now wish to use the code below to insert them into the DB. But it doesn't work! When I run the script it appears to work but the DB does not get updated. Can someone take a look at this and tell me what I am doing wrong? Thanks. <?php session_start(); require_once('db/db.php'); $sql = "INSERT INTO promocode WHERE code = '$promocode' (clubCard,firstName,lastName,address,additionalAddress,city,state,zip,email,confirmEmail,okToContact,q1,q2yes,q2no,q3,q4,q5,q6,q7,q8,q9) VALUES ('$clubCard','$firstName','$lastName','$address','$additionalAddress','$city','$state','$zip','$email','$confirmEmail','$okToContact,'$q1','$q2yes','$q2no','$q3','$q4','$q5','$q6','$q7','$q8','$q9')"; ?> Thank You for your Time Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 2, 2007 Share Posted July 2, 2007 You need to execute the query, not just define the query string, AND the conditional WHERE usually belongs at the end of the query string. $sql = "INSERT ..... WHERE condition = ..."; $result = mysql_query($sql) or die(mysql_error()); // execute the query Quote Link to comment Share on other sites More sharing options...
skali Posted July 2, 2007 Share Posted July 2, 2007 Don't use where clause in insert statement... Below is the syntax that can be used. INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [iGNORE] [iNTO] tbl_name [(col_name,...)] VALUES ({expr | DEFAULT},...),(...),... [ ON DUPLICATE KEY UPDATE col_name=expr, ... ] Or: INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [iGNORE] [iNTO] tbl_name SET col_name={expr | DEFAULT}, ... [ ON DUPLICATE KEY UPDATE col_name=expr, ... ] Or: INSERT [LOW_PRIORITY | HIGH_PRIORITY] [iGNORE] [iNTO] tbl_name [(col_name,...)] SELECT ... [ ON DUPLICATE KEY UPDATE col_name=expr, ... ] Quote Link to comment Share on other sites More sharing options...
tqla Posted July 2, 2007 Author Share Posted July 2, 2007 Oops. I feel kinda dumb for that one. Okay I changed it to: <?php session_start(); require_once('db/db.php'); $sql = "INSERT INTO promocode (clubCard,firstName,lastName,address,additionalAddress,city,state,zip,email,confirmEmail,okToContact,q1,q2yes,q2no,q3,q4,q5,q6,q7,q8,q9) VALUES ('$clubCard','$firstName','$lastName','$address','$additionalAddress','$city','$state','$zip','$email','$confirmEmail','$okToContact,'$q1','$q2yes','$q2no','$q3','$q4','$q5','$q6','$q7','$q8','$q9') WHERE code = '$promocode'"; $result = mysql_query($sql) or die(mysql_error()); // execute the query ?> But I get this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'yes','','','','','','400-600','','','message') WHERE code = 'L12 Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 2, 2007 Share Posted July 2, 2007 My apologies. If you are ADDING to a database you don't need a WHERE. If you are UPDATING a database you do need a WHERE (to tell the db which record to change. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 2, 2007 Share Posted July 2, 2007 You seem to be relying on "register_globals" being on. session_register is deprecated. You should get the variables from the $_SESSION array. Quote Link to comment Share on other sites More sharing options...
tqla Posted July 2, 2007 Author Share Posted July 2, 2007 Hi Andy. That's right!! You just gave me an idea! Originally I was trying to add info to a row that already had a "code" in it. Now I'm just going to create a new table for the final information. Thanks!! Barand. Yes I am using $_SESSION but it's elsewhere in the script. Thanks though! Thanks AndyB, Skali, and Barand. Ticket closed! Yeah! 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.