View Single Post

  #1 (permalink)  
Old 01-09-2005
Steve
 
Posts: n/a
Default Redirect Error Reported As SQL Syntax Error

I just spent waaaaaaaaaaaayy too much time trying to track down an error that was incorrectly reported just now, and I would like to see if someone
can explain to me why it was reported that way.

The purpose of the code is simply to delete a record and then redirect back to the page where the delete was started. The code looks like this:

elseif ($_GET[action] == "delete")
{
$query = "delete from product_subcategory2 where product_sku=$_GET[product_sku] and subcategory2_id=$_GET[subcategory2_id]";
$result = mysql_query($query) or die (mysql_error());
$affected_rows = mysql_affected_rows();

if ($affected_rows == 1)
{
header("Location:product.php?action=edit&product_s ku=$product_sku");
}
else
{
do_header();
echo("<center><p class=\"body\">Unable to delete Subcategory2. Please try again.</p>");
echo("<a href=\"product.php?action=edit&product_sku=$produc t_sku\">Edit Product</a>");
do_footer();
}
}

The SQL was find, but the error I had was in the header line. What I had was this:

header("Location:product.php?action=edit&product_s ku=<?php echo $product_sku?>");

so since I was already in PHP, I didn't need the "<?php echo" for $product_sku.

The problem was that the error message I got was "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version
for the right syntax to use near '' at line 1." Aside from being extremely descriptive (yeah, right), the error message had nothing to do with my SQL
syntax, since it executed fine. Can anyone explain why an error with header() was reported as an SQL syntax error?

Thanks.

Steve
Reply With Quote