Page 1 of 1
MySQL Delete Syntax
Posted: Fri Jan 17, 2003 7:14 am
by TomGeorge
Hi again,
Was just wondering if anyone had any suggestions for the following code as it is not working.
$query = "DELETE FROM $daydel WHERE hours=$hours AND minutes=$minutes)";
There is no problem at all with the variables form what I can gather.
Your help would be much appreciated as always
Thanks,
Tom -
tl.george@virgin.net
Posted: Fri Jan 17, 2003 7:27 am
by volka
remove the ) after $minutes
perform the query like
Code: Select all
$result = mysql_query($query, $conn) or die($query .' :'. mysql_error());
to find those errors
Yup, that did it!
Posted: Fri Jan 17, 2003 8:00 am
by TomGeorge
Ok, yes that worked fine thanks! Didn't see that in there, that was a left over from a previous attempt! Finally, anyone got an idea as to why the following won't work?
$query = "DELETE FROM `$day`";
To empty a table.
Regards
TG
Posted: Fri Jan 17, 2003 8:05 am
by volka
is there anything in mysql_error() ?
does $query contain what you expect ( echo $query; ) ?
you might also use "TRUNCATE tablename" but it will reset the auto-increment field to 0 (if there is).
Posted: Fri Jan 17, 2003 8:19 am
by TomGeorge
Below is the code I am using. I keep getting the "Illegal Query 1" response. Also, I tried putting in the line which you suggested for debugging but it couldn't parse it.
<?php
if (!$link = mysql_connect("localhost", "EGKK", "sitelink"))
exit("Unable to make a connection to the database");
if (!mysql_select_db("EGKK", $link))
exit("Unable to select the database");
// Define a SQL Select Query
$query = "TRUNCATE $day ";
if (!$result = mysql_query($query, $link))
exit("Illegal query 1");
?>
Regards
TG
Posted: Fri Jan 17, 2003 8:22 am
by volka
Posted: Fri Jan 17, 2003 9:46 am
by TomGeorge
Ok it's working super now, thanks a lot everyone!
TG
