Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.