views:

14

answers:

3
 $sql = "UPDATE `$db_name`.`$tbl_name` SET `u_code` = '$u_code' WHERE `$tbl_name`.`email` = `$mail`;";
        $result=mysql_query($sql);

Whenever an email id (eg: [email protected]) is entered and the query is run then error occurs (No such e-mail exists in the database , Although it is present) but after some experiments it is found that instead of entering the email-id (eg: [email protected]) the word "email" is entered and the query is run...it works..but at the same time disturbs whole column {u_code} by changing the value to $u_code for all the database present.

So the problem seems to be in the MySQL query....but I can figure it out.

Thanks for the help! :)

+1  A: 

try this:

$sql = "UPDATE `{$db_name}`.`{$tbl_name}` SET `u_code` = '{$u_code}' WHERE `{$tbl_name}`.`email` = '{$mail}';";
        $result=mysql_query($sql);

first put your $xxx inside of a "" string into brackets. that makes it perfectly safe to use a variable directly inside of a string. second: you should have written '$mail' instead of `$mail`

ITroubs
thanks that worked fine...
tunetosuraj
mark the answer if it worked ;-) so nobody has to watch this question anymore
ITroubs
A: 

I think the problem is that you should use '$mail' instead of the other quotes as email field can be of any string type.

Hope that helps,

Ramon Araujo
A: 

Give this a try. I'm not sure why you are using backticks, but they are probably messing you up:

$sql = "UPDATE $db_name.$tbl_name SET u_code = '$u_code' WHERE $tbl_name.email = '$mail';";
       $result=mysql_query($sql);
Stargazer712