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>

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

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.

Thanks I will give it a try

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);

Just read the error message carefully.
And then erase one of the double "INTO into" from your query.

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);

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.