1

beginner in php and having a lot of trouble nailing down my syntax error for an update data query. Here is the query.

    $sethere = "UPDATE `".$_currentclass."` 
    SET `".$_date."` = 1 
    WHERE studentid = `".$_idNum."`";

Error I'm getting just says "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use at line 1."

Should be noted that the SET line is changing a boolean value which defaults to 0, and I want to change it to 1. I've tried tons of different permutations with no luck. Any help would be much appreciated.

  • 2
    You should use [Prepared Statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) instead of concatenating your queries, since it's much safer. Are you using `mysql_*`, `mysqli_*` or `pdo`? – M. Eriksson May 08 '17 at 05:01
  • remove the backticks from $_idNum variable – Sudhir Bastakoti May 08 '17 at 05:02
  • try this- `$sethere = "UPDATE ".$_currentclass." SET ".$_date." = 1 WHERE studentid = ".$_idNum;` and do `echo $sethere;` and run this query in mysql. – Bhaskar Jain May 08 '17 at 05:02
  • 1
    Possible duplicate of [When to use single quotes, double quotes, and backticks in MySQL](http://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql) – M. Eriksson May 08 '17 at 05:03
  • Removing the backticks from $_idNum did it, thanks so much for your guys help, and I will look into using Prepared Statements, like I said, I'm just a beginner. – Cole Arnholt May 08 '17 at 05:06

3 Answers3

0

Don't use backticks(`) for value section .

$sethere = "UPDATE `".$_currentclass."` 
SET `".$_date."` = 1 
WHERE studentid = ".$_idNum;
Deepak Dixit
  • 1,510
  • 15
  • 24
0
$sethere = "UPDATE table_name SET col_name= 1 where studentid='$value'";

the error you are getting because you are not using the syntax according to the sql version. let me what version of php and sql you use

Prashant
  • 90
  • 1
  • 12
0
$sethere = "UPDATE ".$_currentclass."
SET ".$_date." = 1 
WHERE studentid = ".$_idNum;
Kalaivani M
  • 1,250
  • 15
  • 29