user3143218
user3143218

Reputation: 1816

PHP: Delete Specific Column Value From SQL Table

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);

Upvotes: 0

Views: 2656

Answers (3)

Liauchuk Ivan
Liauchuk Ivan

Reputation: 1993

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

Upvotes: 6

Lost Koder
Lost Koder

Reputation: 884

To make it works remove , from your query.

Upvotes: 0

Noor
Noor

Reputation: 20150

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.

Upvotes: 1

Related Questions