Problem with value that contains comma

0

When you run this query:

mysqli_query($dbc, "insert into toons values(NULL, $toonId, '$toonName', $admin, '$dna', $bank, $money, $hp, '$inventory', $lastPlace)")

I get this error:

  

You have an error in your SQL syntax; check the manual that   correspond to your MySQL server version for the right syntax to use   near '' ',' ',' ',' 'at line 1

What's causing this?

    
asked by anonymous 31.07.2015 / 21:59

1 answer

3

Database only accepts decimal places with . (period). If you are passing 1,99 on the money variable it is likely to give you problem not only in the bank. Uses a replace in the variable from , to . .

mysqli_query($dbc, "insert into toons values(NULL, $toonId, '$toonName', $admin, '$dna', $bank, str_replace(",", ".", $money), $hp, '$inventory', $lastPlace)")
    
31.07.2015 / 22:14