Jump to content

updating error


ccrevcypsys

Recommended Posts

So i get this error when i try to update the database. And im not sure why it is doing this...

MySQL Error Occured
n1064: 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 'N., `LastName`= Labowe, D.D.S., `EventName`= Endodontic Symposium, `EventDescrip' at line 1
n

QUERY = UPDATE cou ses SET `FirstName`=Stua t N., `LastName`= Labowe, D.D.S., `EventName`= Endodontic Symposium, `EventDescription`= 6 panelists of local endodontists~Drs. Bell, Jarrett, Gray, Luckey, Carmichael, Reeves, and Iwasiuk. 1 hr. of clinical 1 hr. of business mtg., `EventDate`= 2004-10-13 , `EventHours`= 2, `RegNo`= , `SubHead`= WHERE id = 1; 

heres my code

<?php
			if($_POST['EventName']){
			   if($_GET['i']==1){
				$record["FirstName"] = $_POST["FirstName"];
				$record["LastName"] = $_POST["LastName"];
				$record["EventName"] = $_POST["EventName"];
				$record["EventDescription"] = $_POST["EventDescription"];
				$record["EventDate"] = $_POST["year"]."-".$_POST["month"]."-".$_POST["day"];
				$record["EventHours"] = $_POST["EventHours"];
				$record["RegNo"] = $_POST["RegNo"];
				$record["SubHead"] = $_POST["SubHead"];

$where = "id = ".$_GET['e'];
$update = $db->update("courses", $record, $where);
	if($update == TRUE){
	echo "This Section Has Updated";
	}else{
	echo "ERROR ERROR WE ARE GOING DOWN!";
	}
}
}?>

and $_GET['e'] = the id of the query.

Link to comment
Share on other sites

I see two things going on:

 

One there appear to be characters that are being dropped fromt he query. For example "courses" is shown as "cou ses" in your first code black.

 

Second, none of your values are enclosed in single quotes. Where is the code that builds the $where variable?

Link to comment
Share on other sites

Where is the code that builds the $where variable?

that is this

 

$where = 'id = '.$_GET['e];
// The e is the id of the row

n~ link=topic=172446.msg764588#msg764588 date=1197909643]

see this part

`EventDate`= 2004-10-13 , `EventHours`= 2, `RegNo`= , `SubHead`= WHERE id = 1; 

 

after regno, is it like that ....

i added this part

if(!empty($_POST['RegNo']) || !empty($_POST['SubHead'])){

$record['RegNo'] = $_POST['RegNo'];

$record['SubHead'] = $_POST['SubHead'];}

so if it is empty they wont show up.

But there is still the same error

 

and i changed "courses" to 'courses'

and changed all the " to '

 

and the cou ses thing is just my debug error. It doesnt like to parse the r's or n's and i just forgot to change that one before i posted this

 

Link to comment
Share on other sites

There are so many errors here, that it appears solving one just reveals another.. for example:

 

$where = 'id = '.$_GET['e];
// The e is the id of the row

 

is missing a closing single quote on the $_GET element ['e'] :

 

$where = 'id = '.$_GET['e'];
// The e is the id of the row

 

Once all of these little oversights are cleared up, you might get some working code...

 

PhREEEk

Link to comment
Share on other sites

no its there lol its just not on this.

 

it seems the error is coming whenever there is a space or any different char.

Could this be the problem if so then how can i fix it

 

updated code

			if($_POST['EventName']){
				if($_GET['i']==1){
				$record['FirstName'] = $_POST['FirstName'];
				$record['LastName'] = $_POST['LastName'];
				$record['EventName'] = $_POST['EventName'];
				$record['EventDescription'] = $_POST['EventDescription'];
				$record['EventDate'] = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
				$record['EventHours'] = $_POST['EventHours'];
				if(!empty($_POST['RegNo']) || !empty($_POST['SubHead'])){
				$record['RegNo'] = $_POST['RegNo'];
				$record['SubHead'] = $_POST['SubHead'];}

$where = 'id = '.$_GET['e'];
		$update = $db->update("courses", $record , $where);
	if($update == TRUE){
	echo "This Section Has Updated";
	}else{
	echo "ERROR ERROR WE ARE GOING DOWN!";
	}
}

Link to comment
Share on other sites

could it be a prblem with this?

<?php
function update ($tablename, $record, $where)

{

	if(!is_array($record)) die ($this->debug("array", "Update", $tablename));



	$count = 0;



	foreach ($record as $key => $val)

	{

		if ($count==0) $set = "`".$key."`"."=".$val;

		else $set .= ", " . "`".$key."`". "= ".$val;

		$count++;

	}	



	$query = "UPDATE ".$tablename." SET ".$set." WHERE ".$where."; ";

	$this->query = $query;

	mysql_query($query, $this->db);

	if ($this->error()) die ($this->debug());



	if ($this->affected() > 0) return true; else return false;



} // end update

?>

This is my db.inc.php class for the update

Link to comment
Share on other sites

Then when i use a test row that has no spaces just test in every input area i get this error

 

n1054: Unknown column 'Test' in 'field list'
n

QUERY = UPDATE `courses` SET `FirstName`=Test, `LastName`= Test, `EventName`= Test, `EventDescription`= Test, `EventDate`= 2007-12-18 , `EventHours`= 3 WHERE id = 1201; 

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.