1

i have this query:

$key = "particle";
$value = 6

$sql = 
"
UPDATE `B5CGM`.`tac_adaptivearmour`
SET `".$key."points` = '".$key."points' + $value
WHERE"." gameid = $gameid AND shipid = $damage->shipid
";

which after debugging results in this string:

UPDATE `B5CGM`.`tac_adaptivearmour` SET `particlepoints` = 'particlepoints' + 6 WHERE gameid = 2703 AND shipid = 16624 

Basicly, what i want is for my query to take the current value of particlepoints in the DB, and increase it by a certain amount which i set via a variable into the UPDATE string.

Before the query, particlepoints is 6 in the DB. After running above query, i would except the table to hold the value 12 as particlepoints. Instead, its set to 6 - i.e. either it remains as 6, or it is set to 6 without taking the original value into account.

thanks.

C. Finke
  • 129
  • 9
  • 2
    backticks not single quotes around your column names: `UPDATE \`B5CGM\`.\`tac_adaptivearmour\` SET \`particlepoints\` = \`particlepoints\` + 6 WHERE gameid = 2703 AND shipid = 16624` – Mark Baker Oct 12 '15 at 18:01

2 Answers2

1

You can do this by using

$sql = "UPDATE `B5CGM`.`tac_adaptivearmour` SET `particlepoints` = `particlepoints` + 6 WHERE gameid = '".2703."' AND shipid ='". 16624."'";

syntex of this type of query is

UPDATE users SET column_name =column_name+10 WHERE id=4
Here 10 is the number by which i want to increase the value of colunm

here column_name field should be numeric. Hope It will help you. Happy coding.

0

Actually you'r mission a acute symbol(`).

    $sql = "
    UPDATE `B5CGM`.`tac_adaptivearmour`
    SET `".$key."points` = `".$key."points` + $value
    WHERE"." gameid = $gameid AND shipid = $damage->shipid
    ";
Payer Ahammed
  • 887
  • 1
  • 5
  • 16
  • 1
    Why should the OP try this? A good answer will always have an explanation of what was done and why it was done that way, not only for the OP but for future visitors to SO. – Jay Blanchard Oct 12 '15 at 18:07