简体   繁体   English

无法在MySQL表中更新字段电子邮件(使用PDO)

[英]Field email not updating in MySQL table (using PDO)

I have a query running on a site that updates a user's profile. 我有一个查询正在更新用户个人资料的网站上运行。 It updates every field but the email field as it should. 它更新每一个领域,但电子邮件领域,因为它应该。 Actually it's not doing anything at all with the email field. 实际上,它对电子邮件字段完全不做任何事情。

I define my $email variable as such: 我这样定义$ email变量:

$email = str_replace(" ", "", trim($_POST['email']));

And then I use my database wrapper to update it: 然后,我使用数据库包装程序对其进行更新:

MySQL::do_query(
    $db, 
    "UPDATE customer 
    SET 
        email=?,
        firstname=?, 
        surname=?, 
        phonenumber=?, 
        street_address=?, 
        postcode=?, 
        city=?, 
        extra_2=?,
        ssn=?,
        password=?
    WHERE customer_id=? 
    AND password=?", 
    array($email, $firstname, $surname, $phone, $address, $zip, $city, $extra_2, $ssn, StringConverter::generate_hash($email, $_POST['pw']), $customer, StringConverter::generate_hash($email, $_POST['pw']))
);

But, then to the problem, it doesn't update the email field. 但是,接着问题来了,它不会更新电子邮件字段。 Every other field it updates just fine. 它更新的所有其他字段都很好。 I've tried running a separate query updating just the email, that doesn't work either. 我试过运行一个单独的查询, 更新电子邮件,这也不起作用。

It works fine when inserting, just not updating. 插入时效果很好,只是不更新​​。 And by this point I have no idea what could be wrong. 至此,我不知道可能出什么问题了。 And the $email variable holds the correct email address, although the query seems to ignore it. 尽管查询似乎忽略了它,但$ email变量保留了正确的电子邮件地址。 Any ideas? 有任何想法吗?

Have you tried updating multiple things along with the email? 您是否尝试过与电子邮件一起更新多项内容? I'm guessing not, because I think if you change the email, then the entire update will not perform correctly... This is because you use $email in StringConverter::generate_hash($email, $_POST['pw']) , but if the email is changed, then the row won't meet the password check in the where clause. 我猜不是,因为我认为如果您更改电子邮件,则整个更新将无法正确执行...这是因为您在StringConverter::generate_hash($email, $_POST['pw'])使用$email ,但是如果更改了电子邮件,则该行将不符合where子句中的密码检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM