Form in PDO to update data

后端 未结 1 1073
闹比i
闹比i 2021-01-16 18:34

I\'ve been looking around and even here on the site, but I can not find the correct syntax in PDO to update data, such as the data of a user profile.

You could give

1条回答
  •  无人及你
    2021-01-16 19:15

    First I'll explain some of the changes I made to your code.

    1) Back-ticks are not required unless you are using a reserved word, so I removed them

    2) You are already defining $id as $id = $_SESSION['memberID']; so I changed $stmt->bindParam(":id", $_SESSION['memberID'], PDO::PARAM_STR);

    3) If you are binding your parameters, you don't need to execute with an array, so I changed $stmt->execute(array(':email' => $_POST['email'], ':location' => $_POST['location'], ':id' => $id)); to $stmt->execute();

    4) The action in your form must be echoed.

    This is the resulting process

    prepare($sql);
        $stmt->bindValue(":email", $email, PDO::PARAM_STR);
        $stmt->bindValue(":location", $location, PDO::PARAM_STR);
        $stmt->bindValue(":id", $id, PDO::PARAM_STR);
        $stmt->execute();
    }
    ?>
    

    This is the resulting form (easier to read with indentations)

    Happy Coding !

    0 讨论(0)
提交回复
热议问题