无法更新特定于表的行

时间:2013-07-01 13:45:25

标签: php sql row

我一直在尝试多种方法来更新名为juytdb的sql数据库中的特定行,其中表users具有列名usernameemail。首先,我尝试连接,连接成功,

$localhost = "localhost";
$dbuser = "google";
$dbpass = "";
$dbname = "juytdb";



$connect = mysql_connect($localhost ,$dbuser ,$dbpass);

mysql_select_db($dbname, $connect);

现在我想更新我使用的特定行

session_start();
$username = $_SESSION['var']; //acutally users are logged so I just need to add their email

$email = $_POST['email']; //value I got from an inputbox


    UPDATE users
SET email='google@gmail.com';
WHERE username='billy';

这不起作用,我也试过

$sql = "UPDATE 'users' SET 'email' = '$email' WHERE 'username' = '$username'";
mysql_query($sql);

此外,电子邮件的默认值设置为“not added

2 个答案:

答案 0 :(得分:1)

你有单引号,你应该有反引号。试试这个:

$sql = "UPDATE `users` SET `email` = '$email' WHERE `username` = '$username'";

答案 1 :(得分:1)

试试这个:

    $sql = "UPDATE users SET email = '".$email."' WHERE username = ".$username;