I have a form that requires the user to confirm their email address, the link is sent to the user as
http://app.myurl.org/h/activate.php?email=useremail%40gmail.com&key=80fddb7fa21dd2e2639ae5ec82b9d511&api=8a2d01d7411ec2488307744ddf070a4d
User accesses activate.php
I'm trying to get email, keyand apifrom the URL-addresses.
Then I try to update the user table and registry table .
wrightway_roster Table column to update - Activation
wrightway_users Table column to update - groups
They both pass the unique value of the random MD5 hash. Everything runs smoothly, just not a TRANSACTION request.
<?php
include ('database_connection.php');
if (isset($_GET['email']) && preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/', $_GET['email'])) { $email = $_GET['email']; }
if (isset($_GET['key']) && (strlen($_GET['key']) == 32)) { $key = $_GET['key'];}
if (isset($_GET['api']) && (strlen($_GET['api']) == 32)) { $API = $_GET['api'];}
if (isset($email) && isset($key)) {
mysqli_query($dbc, "START TRANSACTION");
$result_activate_account = mysqli_multi_query($dbc,"
UPDATE table_users SET groups=[99] WHERE(pinAPP_API ='$API') LIMIT 1;
UPDATE wrightway_roster SET Activation=NULL WHERE(email ='$email' AND Activation='$key')LIMIT 1;
");
if ($result_activate_account !== false) {
mysqli_query($dbc, "COMMIT");
echo '<div>You may now proceed.</div>';
} else {
mysqli_query($dbc, "ROLLBACK");
echo '<div>Oops !You could not be validated. Please recheck the link or contact your hiring manager.</div>';
}
mysqli_close($dbc);
} else {
echo '<div>An Error Occurred.</div>';
}
?>
PHP has a value of 5.4 Native
both Activationand groups varchar
These queries work and do exactly what is intended.
"UPDATE wrightway_users SET groups='[99]' WHERE(pinAPP_API ='$API') LIMIT 1;";
UPDATE wrightway_roster SET Activation=NULL WHERE(email ='$email' AND Activation='$key')LIMIT 1";
I used one request or for what I need for this, I wrote above to use transactions.
if (isset($email) && isset($key)) {
$query_activate_account = "UPDATE wrightway_users SET groups='[99]' WHERE(pinAPP_API ='$API') LIMIT 1;";
$result_activate_account = mysqli_query($dbc, $query_activate_account);
if (mysqli_affected_rows($dbc) == 1)
{
echo '<div>You may now proceed.</div>';
} else {
echo '<div>Oops !You could not be validated. Please recheck the link or contact your hiring manager.</div>';
}
mysqli_close($dbc);
} else {
echo '<div>An Error Occurred.</div>';
}