updating records with prepared statements, checking if update worked

后端 未结 4 1846
一个人的身影
一个人的身影 2021-01-14 02:16

I have a query that updates a record on my database, it works fine but i wanted to know how to check if the update has happened so i can return true and display the right me

4条回答
  •  一个人的身影
    2021-01-14 03:00

    check if below works:

    $query = "UPDATE user
            SET password = ?
            WHERE email = ?";
    
    if($stmt = $conn->prepare($query)) {
        $stmt->bind_param('ss', $pwd, $userEmail);
        if ($stmt->execute()) {
            // Worked...
        } else {
            // Didn't work...
        }
    }
    

提交回复
热议问题