-1

I am using pretty much all variables in my query and i am pretty sure my syntax is wrong somewhere. I have tried a lot of different ways to setup my query. Basically im trying to update a specific row with the id, and the column that is the variable $loc.

    mysqli_query($con,"UPDATE `" . $tbvbr . "` SET $loc='".$addscore."' WHERE pid='".$pn."' ");

i also tried

   mysqli_query($con,"UPDATE `" . $tbvbr . "` SET $loc='$addscore' WHERE pid='$pn' ");

and

   mysqli_query($con,"UPDATE `" . $tbvbr . "` SET $loc=$addscore WHERE pid=$pn ");

Thanks

2
  • Have you tried adding a call to mysqli_error()? It'll tell you what the issue is.
    – andrewsi
    Commented Sep 15, 2013 at 0:00
  • Your code is vulnerable to SQL injection. You need to use the appropriate method of your database library to escape your data prior to making the query.
    – Matt Ball
    Commented Sep 15, 2013 at 0:01

2 Answers 2

1
$sql = "UPDATE `" . $tbvbr . "` SET " . $loc . " = '" . $addscore . "' WHERE pid= '" . $pn . "'";
mysqli_query($con,$sql);
1
  • Thanks for your help. It works great! And i see what i need to do in the future.
    – st15jap
    Commented Sep 15, 2013 at 0:55
0

Does this work?

mysqli_query($con,"UPDATE ".$tbvbr." SET ".$loc." = '".$addscore."' WHERE pid = ".$pn);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.