0
mysql_query() [[url]http://www.mysql.com/doc]:[/url] 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 'into kiwanis_info ( 'identity', 'firstnam', 'lastnam', 'phonenum', 'emailaddr', ' at line 1

Above is waht I get when inserting into a file from a class. The code looks as follows:

function addstate($ent, $errmsg, $identity) {
	var_dump($ent);
	$ent['identity'] = 0;
    echo $query = "INSERT INTO into kiwanis_info ( 'identity', 'firstnam', 'lastnam', 'phonenum', 'emailaddr', 'address1', 'city1', 'state1', 'zipcode1', 'infrequest', 'organ')
	values ('".$ent['identity']."', '".$ent['firstnam']."', '".$ent['lastnam']."', '".$ent['phonenum']."', '".$ent['emailaddr']."',
	'".$ent['address1']."', '".$ent['city1']."', '".$ent['state1']."', '".$ent['zipcode1']."',
    '".$ent['infrequest']."', '".$ent['organ']."')";
	$result1 = mysql_query($query);
    if ($result1) {
	  $this->identity = mysql_insert_id();
	  $identity = $this->identity;
	  $this->errmsg = "Information record $identity was added "; } 
	else  { $this->errmsg = "ERROR ... Information record not added"; }
    return $this->errmsg;
	return $this->identity;
     }

Don Johnston, e-mail: <EMAIL SNIPPED>

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

3
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by donjohnston
0

I also meant to add that the error occurs on $result = mysql_query($query);

0

Just looking at it real quick is identity your primary key and set for auto-increment? If so then do not attempt to set the value as the system will automatically fill it in.

0

I removed the identity field and even changed $result 1 to $result. I get the following:Warning: mysql_query() [http://www.mysql.com/doc]: 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 'into kiwanis_info ( 'firstnam', 'lastnam', 'phonenum', 'emailaddr', 'address1', ' at line 1 in C:\wamp\www\Hicksville PHP\Hicksville_Infoc.php on line 97
Line 97 is $result = mysql_query($query);

0

Thanks I can't believe I missed that. I am now getting: Warning: mysql_query() [http://www.mysql.com/doc]: 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 ''firstnam', 'lastnam', 'phonenum', 'emailaddr', 'address1', 'city1', 'state1', '' at line 1 in C:\wamp\www\Hicksville PHP\Hicksville_Infoc.php on line 97. The query is as follows: $query = "INSERT INTO kiwanis_info('firstnam', 'lastnam', 'phonenum', 'emailaddr', 'address1', 'city1', 'state1', 'zipcode1', 'infrequest', 'organ')
values ( '".$ent."', '".$ent."', '".$ent."', '".$ent."',
'".$ent."', '".$ent."', '".$ent."', '".$ent."',
'".$ent."', '".$ent."')";
$result = mysql_query($query);

0

Do not use the apostroph ' to mark column names. Either drop the apostroph (which I always do) or use the backtick ` for column names.

0

Thanks Smantscheff. It works I removed the apostrophes and left the names to stand alone. Thanks Again.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.