...

View Full Version : Syntax error from query??



sted999
04-15-2009, 03:07 PM
Hiya all.
I am a newbie to MySQL and PHP so appologies if this is a daft error, i just cant see what is wrong?? What i am trying to do is query the database based on 2 conditions and delete the match.

Here is my query -

$query = mysql_query(sprintf("DELETE * FROM Journey WHERE journeyName='$jName' AND loginName='%s'", mysql_real_escape_string(trim($_COOKIE['loginName'])))) or die ('SQL Error: ' . mysql_error());

But when i run the query i am getting this error message -

SQL Error: 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 '* FROM Journey WHERE journeyName='supermarket' AND loginName='hannahMc1'' at line 1

I just cant see what is wrong with it? Can anyone help?
Thank u so much, Stephen.

abduraooft
04-15-2009, 03:11 PM
DELETE FROM Journey ........
No need to specify the columns as we do in SELECT, since it's not possible.
See http://dev.mysql.com/doc/refman/5.0/en/delete.html

sted999
04-15-2009, 03:23 PM
Removing the asterix just leaves me with this error message now -


SQL Error: Query was empty

??? Im confused why its not working :confused:

abduraooft
04-15-2009, 03:38 PM
Im confused why its not working Post rest of your code.

Killermud
04-15-2009, 03:40 PM
That means that the criteria you have given points to no record in your database, try checking your WHERE criteria...

sted999
04-15-2009, 03:42 PM
<?php
if ($_POST['delete'] == 'Delete this ride')
{
$jName=($_POST['deleteRide']);

error_reporting(E_ALL);

include ('connect.php');
mysql_select_db("a6188092") or die(mysql_error());

if (isset ($_COOKIE['loginName']))
{
$query = mysql_query(sprintf("DELETE FROM Journey WHERE journeyName='$jName%' AND loginName='%s'", mysql_real_escape_string(trim($_COOKIE['loginName'])))) or die ('SQL Error: ' . mysql_error());

if ($query)
{
$message = "Your ride has been deleted.";
}

else
{
$message = "Ride not deleted updated.";
}
}
}
echo "$message";
?>

Thanks.

Old Pedant
04-15-2009, 08:55 PM
It's not necessarily an error.

It is *NOT* an error to specify a DELETE or UPDATE to a db that turns out to not remove or change any records. It's just PHP reporting to you that, indeed, no records were deleted/changed. If that's okay with you, just ignore the message.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum