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