I want to update a email field with php but the sql doesn't seems to be working.
我想用php更新一个电子邮件字段,但是sql似乎没有用。
$email2 = "'testing@example.com'";
$id = "'1'";
$query = "UPDATE `users` SET `email` = $email2 WHERE `id` = $id";
echo $query;
if ($stmt = mysqli_prepare($connection, $query))
{
/* execute statement */
mysqli_stmt_execute($stmt);
/* bind result variables */
mysqli_stmt_bind_result($stmt);
/* fetch values */
while (mysqli_stmt_fetch($stmt))
{
}
/* close statement */
mysqli_stmt_close($stmt);
}
mysqli_close($connection);
I'm new to programming. I hope you guys can help me find the mistake. I use MAMP on my mac. PHP version: 5.6.7.
我是编程新手。我希望你们能帮助我找到错误。我在我的Mac上使用MAMP。 PHP版本:5.6.7。
3 个解决方案
#1
0
Since you are providing everything in your query it self. then try like this:-
由于您自己提供查询中的所有内容。然后尝试这样: -
$email2 = "testing@example.com"; // remove '' quote
$id = "1"; // remove '' quote
$query = "UPDATE `users` SET `email` = $email2 WHERE `id` = $id";
$result = mysqli_query($connection,$query) or die(mysqli_error($connection));
if($result){
// do your stuff
}
mysqli_close($connection);
Note:- try to read the mysqli_*
prepare()
, bind_result()
carefully. then use it. don't go blindly. thanks. Also start step by step.
注意: - 尝试仔细阅读mysqli_ * prepare(),bind_result()。然后使用它。不要盲目。谢谢。也一步一步开始。
#2
1
you can use this:-
你可以用这个: -
$update="update users set email='$email2' where id='$id' ";
#3
1
Your query is not working because you need to add quotes in your field.
您的查询无效,因为您需要在字段中添加引号。
varchar
field always requires quotes because it is a string:
varchar字段始终需要引号,因为它是一个字符串:
$query = "UPDATE `users` SET `email` = '".$email2."' WHERE `id` = $id";
#1
0
Since you are providing everything in your query it self. then try like this:-
由于您自己提供查询中的所有内容。然后尝试这样: -
$email2 = "testing@example.com"; // remove '' quote
$id = "1"; // remove '' quote
$query = "UPDATE `users` SET `email` = $email2 WHERE `id` = $id";
$result = mysqli_query($connection,$query) or die(mysqli_error($connection));
if($result){
// do your stuff
}
mysqli_close($connection);
Note:- try to read the mysqli_*
prepare()
, bind_result()
carefully. then use it. don't go blindly. thanks. Also start step by step.
注意: - 尝试仔细阅读mysqli_ * prepare(),bind_result()。然后使用它。不要盲目。谢谢。也一步一步开始。
#2
1
you can use this:-
你可以用这个: -
$update="update users set email='$email2' where id='$id' ";
#3
1
Your query is not working because you need to add quotes in your field.
您的查询无效,因为您需要在字段中添加引号。
varchar
field always requires quotes because it is a string:
varchar字段始终需要引号,因为它是一个字符串:
$query = "UPDATE `users` SET `email` = '".$email2."' WHERE `id` = $id";