如何在mysql oop中获取一行

时间:2017-01-02 06:53:05

标签: php mysql oop mysqli

我正在更改密码功能。目前只是更改密码。但我想稍微修改一下。如果电子邮件和密码有效,则应更改密码,否则不更改密码。这是我的代码。任何人都可以帮助我吗?

function CHANGE_PASSWORD($conn, $MSG)
{
    $sql = $conn->prepare("UPDATE users SET password = ? WHERE email = ? AND password=?");
    $sql->bind_param("sss", $newpass, $email, $password);
    $email = $_REQUEST["EMAIL"];
    $pass = $_REQUEST["PASSWORD"];
    $newpass = $_REQUEST["NEW_PASSWORD"];

    if ($sql->execute()) {

        if($sql->affected_rows == 0) {
            $json["STATUS"] = "FAIL";
            $json["MESSAGE"] = "Invalid email / password";
        } else {
            $json["STATUS"] = "SUCCESS";
            $json["MESSAGE"] = "Password Update Successful";
        }               
    } else {
        $json["STATUS"] = "ERROR";
        $json["MESSAGE"] = "Please try again later.";
        $json["ERROR"] = $sql->error_list;
    }

    $sql->close();
    return json_encode($json);
    #function ends
}

我的当前网址如下所示

  

http://localhost/safespaces/server.php?REQUEST=CHANGE_PASSWORD&EMAIL=mr.aleem001%40gmail.com&PASSWORD=haioye&NEW_PASSWORD=12345

1 个答案:

答案 0 :(得分:0)

要获取行,请使用

$result = $sql->get_result();
$row = $result->fetch_assoc();

我希望它能帮助