我一直在尝试多种方法来更新名为juytdb
的sql数据库中的特定行,其中表users
具有列名username
和email
。首先,我尝试连接,连接成功,
$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
”
答案 0 :(得分:1)
你有单引号,你应该有反引号。试试这个:
$sql = "UPDATE `users` SET `email` = '$email' WHERE `username` = '$username'";
答案 1 :(得分:1)
试试这个:
$sql = "UPDATE users SET email = '".$email."' WHERE username = ".$username;