TessRay97
TessRay97

Reputation: 121

updating data in a database - prepared statement (PHP)

I'm quite new to php and previously have just been using mysqli for my queries. However I always see people saying to use prepared statements instead, so i went through my project in an effort to change all my queries into prepared statements. This particular query is not updating

        $email = $userDetails['email'];
        $token = bin2hex(random_bytes(16));
        $username = $userDetails['username'];
        $timestamp = date('Y/m/d H:i:s');
        $sql = "UPDATE users SET token = ? AND timestamp = ? WHERE email = ?";
        $stmt = mysqli_prepare($connect, $sql);
        mysqli_stmt_bind_param($stmt,"sss",$token,$timestamp,$email);
        mysqli_stmt_execute($stmt);

Upvotes: 1

Views: 34

Answers (1)

Syscall
Syscall

Reputation: 19780

You are using AND instead of , in your UPDATE query :

$sql = "UPDATE users SET token = ?, timestamp = ? WHERE email = ?";

Upvotes: 1

Related Questions