Jump to content

I get an sql syntax error


KC Computers

Recommended Posts

I am working on a small site that has a calander in it but when I goto update a record it gives me an error. here is the code

the error is on line 84 and all the other updates in that section.

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SaA</title>
</head>

<body>

<script language="php">

$username="root";					//"*********";   username for mysql
$password="";					//"**********";				Password for Mysql
$database="hoguerepair";					//"************";	Mysql Database Name      hoguerepair

// Gets the Information from the Form for Oil Changes

$FirstName=$_POST['Fname'];
$LastName=$_POST['Lname'];
$PhonNumber=$_POST['Phone'];
$CarMake=$_POST['Make'];
$CarModel=$_POST['Model'];
$CarYear=$_POST['Year'];
$EngineType=$_POST['Engine'];
$Date=$_POST['Date'];
$Time=$_POST['Time'];

// Makes sure all fields except the Engine type are filled in

if ($FirstName == "" || $LastName == "" || $PhonNumber == "" || $CarMake == "" || $CarModel == "" || $Date == "" || $Time == "" ){
echo ("Please Fill In All Feilds");
}
echo ( "Thank You ");  //Starts the process of telling the customer thank you for placing the order
echo $FirstName;	   //or that the date and time are already taken
echo (" ");
echo  $LastName;

// Connects to the database


mysql_connect("localhost",$username,$password); //mysql13.000webhost.com     localhost

@mysql_select_db($database)or die( "Unable to select database");

// Checks to see if the Date and time are taken already

$query="SELECT * FROM cal";		//reads database
$result=mysql_query($query);	//Puts database in an array

$num=mysql_numrows($result); 	//This gets the Number of records in the data base
mysql_close();					// Closes the data base

$i="0";
$n="0";
$info = $FirstName . " " . $LastName." phone: ". $PhonNumber ." Car Make: ". $CarMake . " Car Model: ".$CarModel . " Car Year: ".$CarYear;

while ($i<$num) {
$dbdate = mysql_result($result,$i,"Date");
$msday = mysql_result($result,$i,"Day");
$msmonth = mysql_result($result,$i,"Month");
$ms93 = mysql_result($result,$i,"9:30am");
$msday = mysql_result($result,$i,"10:00am");
$msyear= mysql_result($result,$i,"Year");



if ($Date == $dbdate) {
	$dbtime = mysql_result($result,$i,$Time);
	$n++;
	$record = $i;
	$i=$num;



	mysql_connect("localhost",$username,$password); //mysql13.000webhost.com     localhost
	@mysql_select_db($database)or die( "Unable to select database");


	if ($Time == "9:30am") {
			mysql_query("UPDATE cal SET 9:30am ='$info' WHERE Date ='$Date'");
	}

	if ($Time == "10:00am") {
			mysql_query("UPDATE cal SET Month = '$msmonth', Day ='$msday', Year= '$msyear', Date='$dbdate', 9:30am = '$ms93', 10:00am ='$info' 10:30am='', 11:00am='', 11:30am='', 12:00pm = '', 12:30pm = '', 1:00pm = '', 1:30pm='',2:00pm='',2:30pm='',3:00pm='',3:30pm='',4:00pm='',4:30pm='' WHERE Date =$Date");
	}

	if ($Time == "10:30am") {
			mysql_query("UPDATE cal SET 10:30am ='$info' WHERE Date ='$Date'");
	}

	if ($Time == "11:30am") {
			mysql_query("UPDATE cal SET 11:30am ='$info' WHERE Date ='$Date'");
	}

	if ($Time == "12:00am") {
			mysql_query("UPDATE cal SET 12:00pm ='$info' WHERE Date ='$Date'");
	}
	if ($Time == "12:30pm") {
			mysql_query("UPDATE cal SET 12:30pm ='$info' WHERE Date ='$Date'");
	}

	if ($Time == "1:00pm") {
			mysql_query("UPDATE cal SET 1:00pm ='$info' WHERE Date ='$Date'");
	}

	if ($Time == "1:30pm") {
			mysql_query("UPDATE cal SET 1:30pm ='$info' WHERE Date ='$Date'");
	}

	if ($Time == "2:00pm") {
			mysql_query("UPDATE cal SET 2:00pm ='$info' WHERE Date ='$Date'");
	}
	if ($Time == "2:30pm") {
			mysql_query("UPDATE cal SET 2:30pm ='$info' WHERE Date ='$Date'");
	}

	if ($Time == "3:00pm") {
			mysql_query("UPDATE cal SET 3:00pm ='$info' WHERE Date ='$Date'");
	}

	if ($Time == "3:30pm") {
			mysql_query("UPDATE cal SET 3:30pm ='$info' WHERE Date ='$Date'");
	}

	if ($Time == "4:00pm") {
			mysql_query("UPDATE cal SET 4:00pm ='$info' WHERE Date ='$Date'");
	}

	if ($Time == "4:30pm") {
			mysql_query("UPDATE cal SET 4:30pm ='$info' WHERE Date ='$Date'");
	}

echo("<br>");
echo mysql_error();
	echo("<br>");
	}
		else {
	$i++;	
	}
}


	if ($dbtime != "" ) {

		echo (" but we do not have an openning for ");
		echo $Date;
		echo (" at ");
		echo $Time;
		echo (". Please choose a diffrent time");
	exit;
	}
	else {
		echo (" your scheduled oil change is on ");
		echo $Date;
		echo (" at ");
		echo $Time;
		echo (". Please arrive 15 minutes early");

echo ("<br>");
echo $info;

mysql_close();
	}
</script>

</body>
</html>

 

Thank you for your help :D

Link to comment
Share on other sites

mysql_query("UPDATE cal SET 9:30am ='$info' WHERE Date ='$Date'");

and

 

mysql_query("UPDATE cal SET Month = '$msmonth', Day ='$msday', Year= '$msyear', Date='$dbdate', 9:30am = '$ms93', 10:00am ='$info' 10:30am='', 11:00am='', 11:30am='', 12:00pm = '', 12:30pm = '', 1:00pm = '', 1:30pm='',2:00pm='',2:30pm='',3:00pm='',3:30pm='',4:00pm='',4:30pm='' WHERE Date =$Date");

 

the error is:

 

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 '9:30am = 'Christopher J. Crandall Test', 10:00am ='Christopher Crandall phone: 2' at line 1

 

Link to comment
Share on other sites

Colons ( : ) are not valid in mysql field names

What's more, you should never be storing the data is that way -- you've got it backwards.

 

What's more, you posted your DB credentials to the world -- so I'd change them ASAP.

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.