Page 1 of 1

PHP - MYSQL Error

Posted: Sun Jul 23, 2006 11:07 am
by OLIVER
Hi,

I using PHP 4.4.2 and MySQL 4.1.20-community-nt with IIS 6 on windows 2003 server. When I try to insert a row through the PHP code into a mysql table I'm getting the following error in the webpage

"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 ''Quote')' at line 1"

If I use the select statement it's working properly but when I use insert it gives that error. Could anyone plase help me on this issue.

Thanks,
oliver.

Posted: Sun Jul 23, 2006 11:40 am
by m3mn0n
Post code.

Posted: Sun Jul 23, 2006 11:40 am
by bdlang
You're going to have to post your SQL statement and any other code or variables relevant to the statement.

Just based on what you've shown, I'd guess the failure is due to lack of an opening quote for the data 'Quote'.

Solved

Posted: Thu Jul 27, 2006 12:06 am
by OLIVER
Thanks guys, it's the problem with the quote.

Posted: Thu Jul 27, 2006 12:39 am
by RobertGonzalez
When you develop locally you can use the SQL string in your die statement to see the actual query being passed to the database.

Code: Select all

<?php
$sql = 'INSERT INTO `table` (`field`, `otherfield`) VALUES (\'$value\', \'$othervalue\')';
if (!$result = mysql_query($sql))
{
    die('Could not perform insert using <strong>' . $sql . '</strong>: ' . mysql_error());
}
?>