Jump to content



Photo

MySQL Update Unknown Query in WHERE Clause

Answered Go to the full post mysql php

  • Please log in to reply
3 replies to this topic

#1 generalt

generalt

    Neowinian

  • Joined: 09-May 07

Posted 25 November 2013 - 01:13

I'm trying to run a query to update table xcodes. xcodes has two columns: codes and status. I want to update the status of the code contained in $code to 1.

 

$qu = "UPDATE xcodes SET status = 1 WHERE codes = $code";
$re = mysqli_query ($dbc, $qu) or trigger_error("Query: $qu\n<br/>MySQL Error: " . mysqli_error($dbc));

 

When I run the query, I get an error telling me that the code (in the variable $code) is an unknown column! The column is codes, not $code.

 

An error occurred on line 83: Query: UPDATE clickycodes SET status = 1 WHERE (codes = d24rg26p)
MySQL Error: Unknown column 'd24rg26p' in 'where clause'

 

I must have my syntax wrong. I've tried putting $code in brackets {$code} to no avail. What am I doing wrong?



Best Answer +Nik L , 25 November 2013 - 01:17

$qu = "UPDATE xcodes SET status = 1 WHERE codes = '$code'"; Go to the full post



#2 +Nik L

Nik L

    Where's my pants?

  • Tech Issues Solved: 1
  • Joined: 14-January 03

Posted 25 November 2013 - 01:17   Best Answer

$qu = "UPDATE xcodes SET status = 1 WHERE codes = '$code'";

#3 OP generalt

generalt

    Neowinian

  • Joined: 09-May 07

Posted 25 November 2013 - 01:25

Wow. I could have sworn I tried that.

 

Thanks!



#4 +Nik L

Nik L

    Where's my pants?

  • Tech Issues Solved: 1
  • Joined: 14-January 03

Posted 25 November 2013 - 01:28

It's always the simplest things we overlook. Now, next, within your PHP, use the PDO library and turn that into a stored procedure and pass it parameters :)



Click here to login or here to register to remove this ad, it's free!