PHP - MYSQL Error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
OLIVER
Forum Newbie
Posts: 2
Joined: Sun Jul 23, 2006 10:58 am

PHP - MYSQL Error

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Post code.
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post 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'.
OLIVER
Forum Newbie
Posts: 2
Joined: Sun Jul 23, 2006 10:58 am

Solved

Post by OLIVER »

Thanks guys, it's the problem with the quote.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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());
}
?>
Post Reply