0

I got an error of unexpected " in the code shown below

Tried to sum columns and then update each row in a SUM-Cell as I run the code.

$QQ = "UPDATE T_IMB19 SET SUM1=$SUMA, SUM2=$SUMB, TOTAL=$SUMTOT WHERE Navn=$rows['Navn']";
mysqli_query($con,$QQ);

I have echo on the SUMA, SUMB and SUMTOT and they act nicely, but the update doesn't work.

Error : "Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)"

GMB
  • 216,147
  • 25
  • 84
  • 135

2 Answers2

0

just add double quotes again for each after and before single quotes, and then join it with . like below code.

$QQ = "UPDATE T_IMB19 SET SUM1=$SUMA, SUM2=$SUMB, TOTAL=$SUMTOT WHERE Navn='" . $rows['Navn'] . "'";
mysqli_query($con,$QQ);
user3783243
  • 5,368
  • 5
  • 22
  • 41
meotig
  • 76
  • 5
0

You don't need the single quotes for the array key when you're within a string.

$QQ = "UPDATE T_IMB19 SET SUM1=$SUMA, SUM2=$SUMB, TOTAL=$SUMTOT WHERE Navn='$rows[Navn]'";
mysqli_query($con,$QQ);

On a side note you may want to use PDO for making your life easier for SQL queries. More docs about it here

rowen5
  • 1