xuniter Posted January 24, 2011 Share Posted January 24, 2011 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()); } Quote Link to comment https://forums.phpfreaks.com/topic/225500-unexpected/ Share on other sites More sharing options...
fortnox007 Posted January 24, 2011 Share Posted January 24, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/225500-unexpected/#findComment-1164428 Share on other sites More sharing options...
gristoi Posted January 24, 2011 Share Posted January 24, 2011 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" Quote Link to comment https://forums.phpfreaks.com/topic/225500-unexpected/#findComment-1164516 Share on other sites More sharing options...
kickstart Posted January 24, 2011 Share Posted January 24, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/225500-unexpected/#findComment-1164518 Share on other sites More sharing options...
xuniter Posted January 28, 2011 Author Share Posted January 28, 2011 the problem was in server not in the script . The server had installed PHP4, when i changed to PHP5 it worked..... Grrr Quote Link to comment https://forums.phpfreaks.com/topic/225500-unexpected/#findComment-1166624 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.