So I wrote this script, and it works when i dont bind the "Random_Key" and use it as it is, but when I bind the key with bindParam() I am getting a error. Can you see whats going wrong?
PHP Code:
<?php
//Fetches Random_Key from email to use in binding
$Random_Key = $_GET['c'];
//Sets other variables for later use
$ERRmsg = "";
$validCount = 0;
//Opens a connection to MySQL
try {
$wdp = new PDO('mysql:host=localhost; dbname=***********', '***********', '******');
$wdp->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//prepare the SQL statement
$sth = $wdp->prepare(
"SELECT
user_email,
Active
FROM
Users
WHERE
Random_Key = :key
");
//binds the key for safety
$sth->bindParam(':key', $Random_Key);
//Excutes the SQL statement
$sth->execute();
//Sets the statement into an array
$result = $sth->fetch(PDO::FETCH_ASSOC);
$active = $result[Active];
$email = $result[user_email];
//Checks if account already active
if($active == 1) $ERRmsg .= "You have already confirmed this account. <br/>";
if($active == 3) $ERRmsg .="Your account has been disabled for securty reasons, contact the Web Admin for more info";
//checks to see if error message is empty, if so continues if not throws error
if(empty($ERRmsg))
{
//If everything passes connects back to Database and updates to make account active
$update = $wdp->prepare(
"UPDATE
Users
SET
Active = '1'
Where
Random_Key= :key
");
//binds the key for safety
$sth->bindParam(':key', $Random_Key);
//Exectures the update
$update->execute();
echo ("<p>Your account has been confirmed!");
}
else
{
echo $ERRmsg;
}
}
catch (PDOException $ex) {
$msg = $ex->errorInfo;
error_log(var_export($msg, true));
die("<p>Sorry, there was an unrecoverable database error. Debug data has been logged.</p>");
};
?>


Reply With Quote
Bookmarks