sted999 Posted April 15, 2009 Share Posted April 15, 2009 Hiya guys. Im a newbie to MySQL and PHP and im stuck on this problem. When i run this query it is just returning a mysql error? - SQL Error: Query was empty Im not sure why it is doing this as all the fields are in the database and have values i am searching for. Can anybody think what may be wrong? Thanks. <?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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/154208-query-error/ Share on other sites More sharing options...
Mchl Posted April 15, 2009 Share Posted April 15, 2009 Split this $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()); into $sql = sprintf("DELETE FROM Journey WHERE journeyName='$jName%' AND loginName='%s'", mysql_real_escape_string(trim($_COOKIE['loginName']))); $query = mysql_query() or die ('SQL Error: ' . mysql_error(). " Query: $sql"); Quote Link to comment https://forums.phpfreaks.com/topic/154208-query-error/#findComment-810680 Share on other sites More sharing options...
PFMaBiSmAd Posted April 15, 2009 Share Posted April 15, 2009 Your springf() is failing because it does not have the correct number of arguments (values). You should be using both these lines to turn on full php error reporting - ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/154208-query-error/#findComment-810681 Share on other sites More sharing options...
sted999 Posted April 15, 2009 Author Share Posted April 15, 2009 I have used both bits of advice but I still seem to be getting an error - SQL Error: Query: My code now - <?php if ($_POST['delete'] == 'Delete this ride') { $jName=($_POST['deleteRide']); ini_set ("display_errors", "1"); error_reporting(E_ALL); include ('connect.php'); mysql_select_db("a6188092") or die(mysql_error()); if (isset ($_COOKIE['loginName'])) { $sql = mysql_query("DELETE FROM Journey WHERE journeyName='$jName%' AND loginName='%s'", mysql_real_escape_string(trim($_COOKIE['loginName']))); $query = mysql_query() or die ('SQL Error: ' . mysql_error(). " Query: $sql"); if ($query) { $message = "Your ride has been deleted."; } else { $message = "Ride not deleted updated."; } } } echo "$message"; ?> Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/154208-query-error/#findComment-810729 Share on other sites More sharing options...
Mchl Posted April 15, 2009 Share Posted April 15, 2009 This has no chance of working: $sql = mysql_query("DELETE FROM Journey WHERE journeyName='$jName%' AND loginName='%s'", mysql_real_escape_string(trim($_COOKIE['loginName']))); Add the lines PFMaBiSmAd posted at the very top of this script (right after <?php ) [edit] Oh.. and it seems I've made a mistake in my code... This $query = mysql_query() or die ('SQL Error: ' . mysql_error(). " Query: $sql"); should be $query = mysql_query($sql) or die ('SQL Error: ' . mysql_error(). " Query: $sql"); Quote Link to comment https://forums.phpfreaks.com/topic/154208-query-error/#findComment-810742 Share on other sites More sharing options...
okamosy Posted April 15, 2009 Share Posted April 15, 2009 One way to check what is going on is to define the query statement as a variable, that way you can print it out to see what is actually getting executed. Try this: $sql = sprintf("DELETE FROM Journey WHERE journeyName='%s%%' AND loginName='%%%s%%'", mysql_real_escape_string($jName), mysql_real_escape_string(trim($_COOKIE['loginName']))); $result = mysql_query($sql) or die ('SQL Error: ' . mysql_error() . ' Query: ' . $sql); Quote Link to comment https://forums.phpfreaks.com/topic/154208-query-error/#findComment-810745 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.