PHP and SQL maths -
this part of php , sql totally new me need use maths update table.
i have table avis_credits 1 row in table
the table deducts credits user uses system qty_credits, want able add additional credits account per example:
client has 10 credits left purchases 100 credits system must take current credits , add 100 giving me 110 credits. doing manual adding side , updating table expresion.
"update avis_credits set credits='$qty_credit'";
what system looks current credits , adds new credits row.
i have tried
"update avis_credits set credits='<?php echo qty_credit?> + $qty_credit'";
but not working @ all. because trying many functions in 1 string? or because maths equation wrong have no idea how write it?
on first query you're not doing math purely changing value of variable:
"update avis_credits set credits='$qty_credit'";
so credits becomes value of $qty_credit
.
on second query <?php echo qty_credit?>
wrong, you're trying open php tag on open 1 , don't use $
on variable , try sum variable gives error.
"update avis_credits set credits='<?php echo qty_credit?> + $qty_credit'";
this sanitize input , sum value of credits addition of value of variable $qty_credit
:
$sql = sprintf("update avis_credits set credits = credits + '%s'", mysql_real_escape_string($qty_credit));
as side note, may want specify id of account want deposit additional credit otherwise above rule increase credit rows.
$sql = sprintf("update avis_credits set credits = credits + '%s' id = '%s'", mysql_real_escape_string($qty_credit), mysql_real_escape_string($id));
Comments
Post a Comment