dt_gry Posted November 16, 2008 Share Posted November 16, 2008 Hi everyone, 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 'primary WHERE (CustID) = '1121600984'' at line 1. when I am running this code, I have pored over this for about an hour and still cannot find where my syntax error is at. <?php include('config.php'); $Con = mysql_connect($Host, $Usr, $Pass); mysql_select_db("$DB", $Con); $PrefUsr = Usr; $Chk = "SELECT * FROM login WHERE Usr = '$PrefUsr'"; $Result = mysql_query($Chk) or die(mysql_error()); If (mysql_num_rows($Result)) { die("The Username that you entered is already in our system! Please try another."); } Else $CustID = rand(1, 9999999999); $MemStat = JJ; $testID = "SELECT * FROM primary WHERE (CustID) = '$CustID'"; $IDresult = mysql_query($testID) or die(mysql_error()); ; If (mysql_num_rows($IDresult)) { die("That Customer ID Already Exhists."); } Else $primary_insert = "INSERT INTO primary(CustID) VALUES('$_POST[$CustID]')"; $login_insert = "INSERT INTO login(CustID, Usr, Pass, MemStat, Email) VALUES('$_POST[$CustID]', '_$Post[usr]', '$_Post[Pass]', $_POST[$MemStat], '$_Post[Email])"; $basic_insert = "INSERT INTO basic(CustID, Fname, Lname, Ctry, St, City, Zip, CCAcct) Values('$_POST[$CustID]', '$_POST[Fname]', '$_POST[Lname]', '$_POST[Ctry]', '$_POST[st]', '$_POST[City]', '$_POST[Zip], '$_POST[CCAcct])"; If (mysql_query($primary_insert)) { die('Error: ' . mysql_error()); } echo "<br />Primary Key Generated and Inserted Successfuly<br />"; If (mysql_query($login_insert)) { die('Error: ' . mysql_error()); } echo "<br />Login Information Collected and Inserted Successfuly<br />"; If (mysql_query($basic_insert)) { die('Error: ' . mysql_error()); } echo "<br />Basic Information Collected and Inserted Successfuly<br />"; mysql_close($Con); ?> Thanks Quote Link to comment Share on other sites More sharing options...
flyhoney Posted November 16, 2008 Share Posted November 16, 2008 Change this: $testID = "SELECT * FROM primary WHERE (CustID) = '$CustID'"; to this: $testID = "SELECT * FROM primary WHERE CustID = '$CustID'"; Quote Link to comment Share on other sites More sharing options...
flyhoney Posted November 16, 2008 Share Posted November 16, 2008 I would also change this: $primary_insert = "INSERT INTO primary(CustID) VALUES('$_POST[$CustID]')"; to this: $primary_insert = "INSERT INTO primary SET CustID = $_POST[$CustID]"; But I'm not sure what you mean by $_POST[$CustID] Quote Link to comment Share on other sites More sharing options...
Twister1004 Posted November 16, 2008 Share Posted November 16, 2008 Else $CustID = rand(1, 9999999999); $MemStat = JJ; // This is not formed right. //your code : $testID = "SELECT * FROM primary WHERE (CustID) = '$CustID'"; // Correct way : $testID = mysql_query("SELECT * FROM `primary` WHERE [column name] = '$CrustID'"; $testID = mysql_query("SELECT * FROM `primary` WHERE [column name] = '$CrustID'"; $IDresult = mysql_query($testID) or die(mysql_error()); ; If (mysql_num_rows($IDresult)) { die("That Customer ID Already Exhists."); } You didn't define what you wanted to do with that query. 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.