Forum Moderators: coopster

Message Too Old, No Replies

mysql update field set field = field + php var?

mysql update field set field = field + php var

         

m0Fo

3:06 pm on Aug 14, 2009 (gmt 0)

10+ Year Member



Hey guys, I'm trying to code something like:

...
$res = mysql_query("SELECT * FROM temp");
while ($row = mysql_fetch_assoc($res))
{
$Puncte = 0 + $row['Total'];
mysql_query("UPDATE sportivi SET Puncte_08 = (Puncte_08 + ".$Puncte.")") or die(mysql_error());

}

The Puncte_08 field is INT(3).. isn't mysql doing well with updating a field by using a php variable? I can't find any help on google :)

Thanks in advance

andrewsmd

6:11 pm on Aug 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't ask me why but try this
mysql_query("UPDATE sportivi SET Puncte_08 = (Puncte_08 + '{$Puncte}');") or die(mysql_error());

If that doesn't work you can always echo("UPDATE sportivi SET Puncte_08 = (Puncte_08 + '{$Puncte}');"); and insert that query manually and see if it works. Just a warning, realize that saying set somevar = somevalue without a where clause will set every row in that column to that value.