Jump to content

Query error?


sted999

Recommended Posts

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";
            ?>

Link to comment
https://forums.phpfreaks.com/topic/154208-query-error/
Share on other sites

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");

Link to comment
https://forums.phpfreaks.com/topic/154208-query-error/#findComment-810680
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/154208-query-error/#findComment-810729
Share on other sites

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");

 

 

Link to comment
https://forums.phpfreaks.com/topic/154208-query-error/#findComment-810742
Share on other sites

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);

 

Link to comment
https://forums.phpfreaks.com/topic/154208-query-error/#findComment-810745
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.