简体   繁体   English

php / Mysql:UPDATE查询不起作用(而SELECT和INSERT INTO起作用)

[英]php/Mysql : UPDATE query not working (while SELECT and INSERT INTO work)

I have a problem that I am trying to solve for a great number of hours now. 我有一个问题想解决很多小时。

While everything works fine with the SELECT and INSERT INTO query, I am unable to update my database in phpMyAdmin 尽管在SELECT和INSERT INTO查询中一切正常,但是我无法在phpMyAdmin中更新数据库

        <?php

        // Vérification de la validité des informations
        if (isset($_POST['name_last']) AND isset($_POST['name_first']) AND isset($_POST['email']) AND isset($_POST['school']) AND isset($_POST['phone_number']) AND isset($_POST['birth_date']))
        {
            // On rend inoffensives les balises HTML que le visiteur a pu rentrer
            $_POST['login'] = htmlspecialchars($_POST['login']);
            $_POST['name_last'] = htmlspecialchars($_POST['name_last']);
            $_POST['name_first'] = htmlspecialchars($_POST['name_first']);
            $_POST['email'] = htmlspecialchars($_POST['email']);
            $_POST['school'] = htmlspecialchars($_POST['school']);
            $_POST['phone_number'] = htmlspecialchars($_POST['phone_number']);
            $_POST['birth_date'] = htmlspecialchars($_POST['birth_date']);

            $login = $_POST['login'];
            $name_last = $_POST['name_last'];
            $name_first = $_POST['name_first'];
            $email = $_POST['email'];
            $school = $_POST['school'];
            $phone_number = $_POST['phone_number'];
            $birth_dateInput = $_POST['birth_date'];    
            $birth_date = DateTime::createFromFormat('d/m/Y', $birth_dateInput)->format('Y-m-d');

            if (!preg_match("#^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#", $_POST['email']))
            {
            echo 'L\'adresse ' . $_POST['email'] . ' n\'est pas valide, recommencez !';
            }

            else {


            // Insertion
            $req = $bdd->prepare('UPDATE member_student(email, name_last, name_first, school, phone_number, birth_date) SET(:email, :name_last, :name_first, :school, :phone_number, :birth_date) WHERE login = $login');
            $req->execute(array(
            'email' => $email,
            'name_last' => $name_last,
            'name_first' => $name_first,
            'school' => $school,
            'phone_number' => $phone_number,
            'birth_date' => $birth_date
            ));


            echo 'Vos changement ont été pris en compte et votre nouvelle école est ' . $school . "  " . $login . "  " . $email . "  " . $name_last . "  " . $name_first . "  " . $id . "  " . $birth_date;
            ?>

Everything seems to work fine, no errors are returned, and the website displays: "Vos changement ont été pris en compte et votre nouvelle école est ..." 一切似乎都运行良好,没有错误返回,并且网站显示:“ Vo change on onétépris en compte et votre nouvelleécoleest ...”

However, the database in phpMyAdmin is not updating ! 但是,phpMyAdmin中的数据库未更新! Do you have any idea where the problem might come from ? 您是否知道问题可能来自何处? I have checked every variable, the connexion to the database is working just fine, so the problem is, I think, coming from the MySQL query. 我检查了每个变量,与数据库的连接正常,所以我认为问题出在MySQL查询。

Any help would be much appreciated: I am stuck as long as I can't make the update query work ! 任何帮助将不胜感激:只要我无法使更新查询正常工作,我就会陷入困境!

replace this code 替换此代码

$req->execute(array(
                `email` => $email,
                `name_last` => $name_last,
                `name_first` => $name_first,
                `school` => $school,
                `phone_number` => $phone_number,
                `birth_date` => $birth_date
                ));

use this sign ` in database field 在数据库字段中使用此符号`

$req = $bdd->prepare('UPDATE member_student(email, name_last, name_first, school, phone_number, birth_date) 
                SET("'.$email.'", "'.$name_last.'", "'.$name_first.'", "'.$school.'", '.$school.', "'.$birth_date.'") WHERE login='.$login);

try this way 尝试这种方式

Change this: 更改此:

$req = $bdd->prepare('UPDATE member_student(email, name_last, name_first, school, phone_number, birth_date) SET(:email, :name_last, :name_first, :school, :phone_number, :birth_date) WHERE login = $login');

With this: 有了这个:

$req = $bdd->prepare('UPDATE member_student SET email = :email, name_last = :name_last, name_first = :name_first, school = :school, phone_number = :phone_number, birth_date = :birth_date WHERE login = :login');

try this it really works 试试这个,它真的有效

$req = $bdd->prepare('UPDATE member_student SET email = ?, name_last = ?, name_first = ? , school = ? , phone_number = ?, birth_date =? WHERE login = ?'); $ req = $ bdd-> prepare('UPDATE member_student SET email =?,name_last =?,name_first =?,school =?,phone_number =?,birth_date =?WHERE login =?');

$req->execute(array($email, $name_last, $name_first, $school, $phone_number, $birth_date, $login)); $ req-> execute(array($ email,$ name_last,$ name_first,$ school,$ phone_number,$ birth_date,$ login));

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

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