Jump to content

Unexpected ";


xuniter

Recommended Posts

Hi, i am getting the following error message, but everything seems ok in script...

 

Parse error: syntax error, unexpected ';' in /www/zxq.net/htdocs/admin/includes/functions.php on line 27

 

This is the code snippet:

function addCat($cName, $cDesc) {
$query = mysql_query("INSERT INTO categories VALUES(null,'$cName','$cDesc')") or die(mysql_error());
}

Link to comment
https://forums.phpfreaks.com/topic/225500-unexpected/
Share on other sites

what values do $cName and $cDesc give?

By the way why don't you use the following format

mysql_query("INSERT INTO categories (cname, cdesc)
VALUES ('$cName', '$cDesc')") or die(mysql_error());

 

-edit: that way it's less likely to screw up your primary key and keep more clear what value is assign to which column

Link to comment
https://forums.phpfreaks.com/topic/225500-unexpected/#findComment-1164428
Share on other sites

Hi, you would be better if you declared the fields to insert into:

 

mysql_query("INSERT INTO categories (`fileda`, `fieldb`) VALUES ('$cName', '$cDesc')") or die(mysql_error());

 

where field a and field b are the names of the two fields that you wish to insert the values into.

 

The error message you are getting is basically telling you that you have an extra " in your query. This is more than likey being passed into the query by either $cName or $cDesc. echo out these variables and make sure $cName = bob and not  "bob"

Link to comment
https://forums.phpfreaks.com/topic/225500-unexpected/#findComment-1164516
Share on other sites

Hi

 

I can't spot anything wrong there. Could you paste a few lines either side.

 

I don't think it is the contents of a variable as suggested above as you appear to be getting a php error, and extra quotes would not cause such an error to php (might well cause an issue with mysql though).

 

All the best

 

Keith

Link to comment
https://forums.phpfreaks.com/topic/225500-unexpected/#findComment-1164518
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.