How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.
Do more with
// NOT THIS...
mysql_query("UPDATE products SET ProductName='$ProductName', SupplierId='$SupplierId' ,CategoryId='$CategoryId', QuantityPerUnit='$QuantityPerUnit',UnitPrice='$UnitPrice',UnitsInStock='$UnitsInStock',UnitsOnOrder='$UnitsOnOrder',ReorderLevel='$ReorderLevel',Discontinued='$Discontinued'
,LastModifiedDateTime='$LastModifiedDateTime' WHERE ProductId='$ProductId'")
// BUT THIS
$sql
=
"UPDATE products
SET
ProductName = '$ProductName'
, SupplierId = '$SupplierId'
, CategoryId = '$CategoryId'
, QuantityPerUnit = '$QuantityPerUnit'
, UnitPrice = '$UnitPrice'
, UnitsInStock = '$UnitsInStock'
, UnitsOnOrder = '$UnitsOnOrder'
, ReorderLevel = '$ReorderLevel'
, Discontinued = '$Discontinued'
, LastModifiedDateTime = '$LastModifiedDateTime'
WHERE
ProductId = '$ProductId'
"
;
$res = mysql_query($sql);
if (!$res)
{
echo "FAIL: $sql ";
echo "BECAUSE: " . mysql_error();
/* HANDLE ERROR CONDITION HERE */
}
Obviously this is untested code (I don't have your data base) but hopefully it makes for a good example of how to write very readable query strings. Want to find your queries in a large script file? Look for the equal sign in column 1. Need to add columns to the query -- easy! You might want to try deliberately introducing an error into the query and look at the error message output. I think you'll find that "neatness counts" and pays some big benefits when you're debugging.
Premium Content
You need an Expert Office subscription to comment.Start Free Trial