This is my table 'tbl_size'
**Col Name** **Data Type**
size_id int(11)
pd_id int(11)
size_name varchar(20)
size_chart int(6)
qty text
Now I'm trying to update this table with following query
$query="update tbl_size set `qty`='10' where `size_id`=335";
When i run this query in mysql, it works fine but when same thing i tries to do from php then it is updating qty to '0' and not to '10'.
I'm not getting why this is happening. Please help me to solve this problem.
New Updated Code :
// $rowvo['od_qty']=10;
// $row_1['qty']=20;
$sql = "SELECT qty FROM tbl_size WHERE size_id =".$rowvo['size_id'];
$result = dbQuery($sql);
$row_1 = dbFetchAssoc($result);
$pqty=$row_1['qty']-$rowvo['od_qty'];
echo "Total Quantity Available Before Diduction : ".$row_1['qty'];
echo "Sold Quantity : ".$rowvo['od_qty'];
echo "Remaining Quantity : $pqty";
$sql_qty="update tbl_size set `qty`=$pqty where `size_id`=".$rowvo['size_id'];
echo "$sql_qty<br>";
$result_qty=mysql_query($sql_qty) or die('Error : '.mysql_error());
echo "No of Rows Affected : ".mysql_affected_rows()."<br>".mysql_error(); // 1
New Code with PDO :
try {
$b=$a->prepare("update tbl_size set `qty`=:qty where `size_id`=:size");
$b->bindValue(":size",$size_id);
$b->bindValue(":qty",$pqty);
$b->execute();
} catch(PDOException $ex) {
echo "An Error occured!"; //user friendly message
}
and var_dump($ex)=NULL
mysql_*functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.