jason m
jason m

Reputation: 6835

query was empty error

If i submit the below SQL generated in the error line indicated it runs fine, yet in PHP it tells me the "query was empty".

Any idea why?

The string generated for example is as follows:

update LOTS set packageID = "" where packageID ='AS0610'

If i submit this query manually as i said there is no error. I have tried substituting the "" for '' and it does not seem to fix the issue.

<?


$delID = stripslashes($_COOKIE['delID']);
$delType = $_COOKIE['delType'];
$conn=mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
echo $conn;


if($delType=="packageID"){
    $sqlLots = 'update LOTS set packageID = "" where packageID ='.$delID;

    echo $sqlLots;

    //returns "Quer was empty" on below line.
    $result = mysql_query($sqlLOTS) or die(mysql_error());

    $sqlLOTS = 'delete from PACKAGES where '.$delType.' = '.$delID;

}else{
    $sqlLOTS = 'delete from LOTS where '.$delType.' = '.$delID;
}


$result = mysql_query($sqlLOTS); //or die(mysql_error());
echo "<html>";
echo "<script>";
echo "window.location = 'http://www.redIR.info/manage/index.php'";
echo "</script>";
echo "</html>"; 

echo 'a'.$result;



     ?>

Upvotes: 0

Views: 873

Answers (3)

Haroon
Haroon

Reputation: 1155

You are using 2 variables - $sqlLOTS and $sqlLots.

You should use 1 variable name and use that through the whole process of creating your query.

Additionally I would define the variable you decide to use, before your if statement starts.

I would also think about using the PDO library, with prepared statements.

Upvotes: 3

John Lawrence
John Lawrence

Reputation: 2923

You are using $sqlLOTS when you run the query:

$result = mysql_query($sqlLOTS)

But, you are setting $sqlLots:

$sqlLots = 'update LOTS set packageID = "" where packageID ='.$delID;

Variable names are case sensitive so you have two separate variables and $sqlLOTS is indeed empty when you run your query.

Upvotes: 1

ioseb
ioseb

Reputation: 16951

Variable names are case sensitive:

$result = mysql_query($sqlLOTS) or die(mysql_error());

You are initializing variable with different name and using different variable as a mysql_query() parameter. You need to use $sqlLots.

Or change $sqlLots to $sqlLOTS in this line:

$sqlLots = 'update LOTS set packageID = "" where packageID ='.$delID;

Upvotes: 0

Related Questions