Oba
Oba

Reputation: 11

Prepared Statement to Insert and update different table in database

Please How can i use prepared statement to update one table and insert into another table. i did what i no was right but the when i submit the form on that page, it just give me a blank page and nothing happened in the two database see what it look like

$check = "INSERT INTO users(userEmail, password, joinDate, recEmails,
                            isActive, hash, lastUpdated) 
            VALUES (?, ?, NOW(), 1, 0, ?, NOW() ) ";

$stmt = $mysqli->prepare($check);
$stmt->bind_param('sss',$emailAddy,$password,$hash );

$stmt->execute();
$stmt->close();

$check1="UPDATE pin SET status = '1', usedby = ?,WHERE pin = ?";

$stmt = $mysqli->prepare($check1);

$stmt->bind_param('ss',$emailAddy,$pin);                
$stmt->execute();
$stmt->close();

The result i get is this example.com is currently unable to handle this request. I have tried and discovered that the issue is hidden somewhere here, if i remove the update table instruction the code works fine but one i return the issue comes back. Please can anybody help?

Upvotes: 1

Views: 817

Answers (1)

Alon Eitan
Alon Eitan

Reputation: 12025

You have an error here:

$check1 = "UPDATE pin SET status = '1', usedby = ?, WHERE pin = ?";

Change it to (Remove the , after usedby = ?)

$check1 = "UPDATE pin SET status = '1', usedby = ? WHERE pin = ?";

Upvotes: 2

Related Questions