dongluan5740
dongluan5740
2017-01-02 06:53

如何在mysql oop中获取一行

已采纳

I am making a change password function. Currently It is just changing the password. But I want to amend it a bit. If email and password is valid then it should change the password, otherwise not. This is my code. Can anyone help me?

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
}

My Current URL looks like this

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dphg63476 dphg63476 4年前

    To fetch a row, use

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

    I Hope it Helps

    点赞 评论 复制链接分享

相关推荐