0

我一直在尝试许多方法来更新我的 sql 数据库中名为juytdb具有列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

4

2 回答 2

1

尝试这个:

    $sql = "UPDATE users SET email = '".$email."' WHERE username = ".$username;
于 2013-07-01T13:51:00.473 回答
1

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

$sql = "UPDATE `users` SET `email` = '$email' WHERE `username` = '$username'";
于 2013-07-01T13:46:28.683 回答