php - Variable + Number to Database -
i confused great.
i trying press button add 40 sales
in order add 40 need current number of sales used fetch array output number , see '40' set variable tried $varible + 40 set number. not seem working check online , anyhelp awesome!
$query = "select `sales` `sales`"; if ($result=mysqli_query($link, $query)) { $row = mysqli_fetch_array($result); print_r($row); } if ($_post['update']) { echo 'updating...'; $query="update `sales` set `sales` = '$row+40' `sales`.`id` = 1"; mysqli_query($link, $query); echo '<br>successfully updated'; } else { echo 'unsuccessful'; }
as far query goes in mysql don't need 2 separate ones add existing data. query go follows:
update `sales` set `sales` = `sales` + 40 `sales`.`id` = 1;
so code this...
if($_post['update']) { echo 'updating...'; $query = "update `sales` set `sales` = `sales` + 40 `sales`.`id` = 1"; mysqli_query($link, $query); echo '<br>successfully updated'; } else { echo 'unsuccessful'; }
by way, reason code failing right because $row
array. have access key in array data want out of it. right you're trying sum of 40 , array object.
Comments
Post a Comment