Reputation: 119
I'm having trouble updating my postgressdb using update clause where itemid = "$_get['itemid'];
here's my sql code but it returns Warning: pg_query(): Query failed: ERROR:
$sql="UPDATE tbl_item SET itemname='".$_POST['ItemName']."', highqntythreshold='".$_POST['HQThreshold']."', lowqntythreshold='".$_POST['LQThreshold']."', qntyperunit='".$_POST['QPUnit']."', itemtype='".$_POST['IT']."', description='".$_POST['Description']."', WHERE itemid='". $_GET['itemid'] . "';";
$iteminfo = pg_query($sql);
and it also returns "Warning: pg_affected_rows() expects parameter 1 to be resource, boolean given in D:\Wamp\wamp\www\Php\CTea\UpdateItem.php on line 303"
if(pg_affected_rows($iteminfo)==1)
{
$msg = "Successfully added new Item, ".ucfirst($_POST['ItemName'])."!";
}
else
{
$msg = "Error: in saving Item data!...";
}
i think i messed up something but can't figure it out where and what i messed up.
Upvotes: 0
Views: 67
Reputation: 1269673
The problem is (at least) in this part:
$_POST['Description']."', WHERE itemid='". $_GET['itemid'] . "'
There is a comma before the where
, so you want:
$_POST['Description']."' WHERE itemid='". $_GET['itemid'] . "'
In general, though, you should just print out the query string after variable substitution. About 98% of the time, the error is obvious and you can fix it quickly.
Upvotes: 1