views:

37

answers:

2
mysql_query("insert into mytable (flow,holderid,amount,operator,ip,product,taskid,comment)values('-1','$memberid','$sum+5','$memberid','$ip','Expertise','$taskid','Publish a problem or task') ")or die(mysql_error());

I get an error about

'$sum+5'

MySQL doesn't treat it as an and operation, how to resolve this problem?

+1  A: 

Assuming you're using PHP with MySQL, concatenate the query like: '".($sum+5)."'

Also, you would want to put curly brackets '{$variable}' around your variables that remain within the double quotes, otherwise it will just read it as text you want inserted rather than a variable.

munch
+1  A: 

If you want MySQL to perform the addition, drop the single quotes around the addition; they make MySQL interpret the expression as a string (just as PHP would). If you want PHP to perform the addition, do as fucla writes.

outis