0

im busy trying to set multiple fields in my DB and it is not working for some reason. Can you take a look and let me know where i have gone wrong? Thank you

<?php
error_reporting('E_ALL');
include 'db_header.php';

$id = $_GET['ID'];
$bronzeTokens = $_GET['bronzeTokens'];
$silverTokens = $_GET['silverTokens'];
$goldTokens = $_GET['goldTokens'];
$platinumTokens = $_GET['platinumTokens'];

$sql = "UPDATE Player SET bronzeTokens = $bronzeTokens, goldTokens = $goldTokens, silverTokens = $silverTokens, platinumTokens = $platinumTokens WHERE ID = $id";
$result = $conn->query($sql);
?>
rutter
  • 11,242
  • 1
  • 30
  • 46
John Esslemont
  • 87
  • 1
  • 3
  • 10
  • 1
    How do you know it's not working? Do you get an error message? – WillardSolutions Mar 01 '17 at 22:03
  • What datatype are these fields? If they're strings, you need to put the values in quotes. But it would be best if you use parametrized queries. – Barmar Mar 01 '17 at 22:04
  • They are ints, the reason i know its not working as the DB is not updating. I can echo out the values which is good i know they are updated, but the DB is not updating? – John Esslemont Mar 01 '17 at 22:05
  • 1
    Strongly recommend you use a [parameterized query](http://stackoverflow.com/questions/4712037/what-is-parameterized-query) to avoid SQL injection attacks. You should probably also check for error codes to see if a query succeeded or failed (and why). – rutter Mar 01 '17 at 22:16
  • Ok was me being totally stupid, i forgot to set the id – John Esslemont Mar 01 '17 at 22:19
  • @rutter & burmerThanks guys gonna check these out, i heard of them but never looked into them! Thanks! – John Esslemont Mar 01 '17 at 22:24

0 Answers0