Tell me more ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am getting this error when I execute this script:

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 'table) VALUES (3, 4)' at line 1

This is my code:

$tableNum = 3;
$coverNum = 4;

//construct query & execute
$sql = "INSERT INTO orders (covers, table) VALUES ('$tableNum', '$coverNum') ";
$result = mysql_query($sql) or die(mysql_error());
$numrows = mysql_num_rows($result);

//return value
if($numrows > 0)
   {
    echo 'Success';
   }
else
   {
    echo 'UnSuccessful';
   }

What is wrong?... Many thanks for any help on issue.

share|improve this question
Your 'table' column isn't a reserved word in MySQL? If yes, try using ``, '', "" or [] to make it an ordinary word. – Marian Feb 21 at 20:05
That cleared up the initial error, thank you. I am now getting this error: mysql_num_rows() expects parameter 1 to be resource I will make new question maybe? – Javacadabra Feb 21 at 20:33
The new error is a PHP error, not a database error. If you're unsure about how to fix it and you want to ask a new question, it should be on Stack Overflow; it would be off-topic on this site. – Jon Seigel Feb 21 at 20:37
sorry your right, no worries. thanks! – Javacadabra Feb 21 at 20:38
add comment (requires an account with 50 reputation)

closed as too localized by Jon Seigel, dezso, Leigh Riffel, Marian, Mark Storey-Smith Feb 22 at 23:57

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

Try this:

$tableNum = 3;
$coverNum = 4;

//construct query & execute
$sql = "INSERT INTO orders (covers, `table`) VALUES ('".$tableNum."', '".$coverNum."') ";
$result = mysql_query($sql) or die(mysql_error());
$numrows = mysql_num_rows($result);

//return value
if($numrows > 0)
   {
    echo 'Success';
   }
else
   {
    echo 'UnSuccessful';
   }
share|improve this answer
add comment (requires an account with 50 reputation)

Not the answer you're looking for? Browse other questions tagged or ask your own question.