Jump to content

php MYSQL error


dt_gry

Recommended Posts

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

;D

Link to comment
Share on other sites

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.

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.