Title: Insert Query not working
Tags: mysql
Question: I have applied a insert query but its giving error .

```$registerquery = mysql_query("INSERT INTO `registration`(`Activation`) VALUES('".$activation."') WHERE email= '". trim($_POST['email']) ."'");
```

Comment: `INSERT`'s don't have a `WHERE` clause. Did you mean to use an `UPDATE`?

Comment: Actually i am going to take the value from the session .thanks for correcting me

Comment: What's the error say, Did you run mysql_connect first, and select a database? Also you should look into other methods of connecting to a sql database. As mysql_ functions are depreciated.

Comment: Past the immediate issue, you are taking `$_POST['email']` directly without any filtering in any way? Bad practice.

Here is the accepted answer: Use update statement instead of INSERT to use where clause

```$registerquery = mysql_query("UPDATE `registration` 
                    SET `Activation` = '".$activation." 
                    WHERE email= '". trim($_POST['email']) ."'"
                 );
```


Here is another answer: if you want just update a column in table so you need an ```UPDATE``` not ```INSERT``` .

and also you should sanitize you POST variable to prevent sql injection.

```  $email = mysql_real_escape_string($_POST['email'])) ;

  $registerquery = mysql_query("UPDATE `registration` 
                              SET `Activation` '".$activation."'
                              WHERE email= '". trim($email) ."'");
```


Please move to PDO or mysqli as mysql is already deprecated.



Here is another answer: It seems you are trying to overwrite an existing value use an UPDATE statement and not an INSERT statement this is the reason why it is not working. INSERT works when you are trying to insert a new value there should not be a condition in it (where clause).


Here is another answer: check this ```registration```(```Activation```) it does not seem correct, the ` should maybe be ' and maybe you should start the query with @ in order to avoid sql injection attack

Comment for this answer: Back ticks (`) are allowed in mysql, are used to denote field names, So should not be used around `registration`. See http://stackoverflow.com/questions/261455/using-backticks-around-field-names

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 4, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:11/16/13', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<mysql>', 'Title': 'Insert Query not working', 'ViewCount': 83, 'id': 20016416, 'user_AboutMe': '<p>I am a Php developer and having a knowledge of core php,Wordpess,magento .\nCurrently Working on Python -Django frame work .</p>\n', 'user_AccountId': 2259483.0, 'user_DisplayName': 'Ranbir Singh', 'user_Reputation': 203.0, 'user_Views': 91.0, 'user_id': 1989906.0}}