-2

First off, yes I have done research and have seen tons of posts like this one. I see the post this is supposed to be a duplicate of but it was not helpful. I am very new with this and do not know how to apply their results to mine. I'm getting this result when running:

Parse error: syntax error, unexpected '$_GET' (T_VARIABLE) in /storage/ssd4/269/2113269/public_html/updateuser.php on line 12

Here is my script:

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
            $sql = "UPDATE Users ". "SET Status = '"$_GET["status"]"' ".
               "WHERE Username = '"$_GET["username"]"'";
if ($conn->query($sql) === TRUE) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . $conn->error;
}

$conn->close();
?>

Thank you a bunch for taking a look. I might be missing a semi-colon somewhere but I've looked over the code for a while. Please let me know!

Luke Deven
  • 66
  • 1
  • 8
  • Add `.` in your query. $sql = "UPDATE Users ". "SET Status = '"$_GET["status"]"' ". "WHERE Username = '".$_GET["username"]."'"; – Jaydeep Mor Jul 01 '17 at 11:29
  • `$sql = "UPDATE Users SET Status = '". $_GET["status"]."' WHERE Username = '".$_GET["username"]."'";` – Praveen Kumar Jul 01 '17 at 11:30
  • you need to concatinate properly like this $sql = "UPDATE Users SET Status = '".$_GET["status"]."' WHERE Username = '".$_GET["username"]."'"; – JYoThI Jul 01 '17 at 11:32
  • I looked at the post this was a "duplicate" of and it was not helpful, thus my post. :/ – Luke Deven Jul 01 '17 at 21:57

3 Answers3

2

You have to concatenate string using .

$sql = "UPDATE Users ". "SET Status = '".$_GET["status"]."' ".
               "WHERE Username = '".$_GET["username"]."'";
B. Desai
  • 16,414
  • 5
  • 26
  • 47
1

You need to concatenate string and variable using dot(.) properly like this

 $sql = "UPDATE Users 
         SET Status = '".$_GET["status"]."' 
         WHERE Username = '".$_GET["username"]."'";
JYoThI
  • 11,977
  • 1
  • 11
  • 26
0

This is because you end and start the statement with " before and after the the GET statement declaration; but haven't put the concatenation . in between the " and GET.

"SELETCT tb FROM db WHERE field = '".GET ['something']."'";

It's also a good habit to wrap the two GET in a IF statement and run the full code if bot Get has some value. Reduce the unnecessar SQL and PHP execution.

Prav
  • 2,785
  • 1
  • 21
  • 30