0

I'm trying to delete a specific column value from an SQL table with php. The table looks like this:

             my_db 
------------------------------------------
 code       | user | email               |
------------------------------------------
 10314343   |  20  | [email protected] |
 13423434   |  22  | [email protected] |
 11342434   |  40  | [email protected] |

What I want to do is update the "code" value to empty on user "20". Here is what I have so far but it's not working:

$tbl_name = mydb;
$getcode = "10314343"


$updateCode = "UPDATE $tbl_name SET code ='', where code ='$getcode'";
$confirmUpdate = mysql_query($updateCode);
2
  • 1
    sidenote: stop using deprecated mysql_* functions. use MySQLi or PDO instead. Here is a good tutorial for PDO. Commented Apr 28, 2014 at 6:37
  • You have an extra , before where Commented Apr 28, 2014 at 6:38

3 Answers 3

6

You should delete comma after code=''. This one should work fine:

$updateCode = "UPDATE $tbl_name SET code ='' WHERE code ='$getcode'";

Comma used when you have to update several fields. For example if yo want to update code and email, you should use sql query like this:

$updateCode = "UPDATE $tbl_name SET code ='', email='[email protected]' WHERE code ='$getcode'";

But after last component you should not paste comma

Sign up to request clarification or add additional context in comments.

Comments

1

The comma in your sql statement after code='' is not important. It is very important that you read about sql and understand it, especially its syntax else you might continue to go into these problem and lose time unnecessarily.

Comments

0

To make it works remove , from your query.

Comments

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.