Ranbir Singh
Ranbir Singh

Reputation: 203

Insert Query not working

I have applied a insert query but its giving error .

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

Upvotes: 1

Views: 92

Answers (4)

echo_Me
echo_Me

Reputation: 37233

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.

Upvotes: 2

Harish Singh
Harish Singh

Reputation: 3329

Use update statement instead of INSERT to use where clause

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

Upvotes: 1

5eeker
5eeker

Reputation: 1027

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

Upvotes: 2

Ovis
Ovis

Reputation: 391

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

Upvotes: 1

Related Questions