Hi,
I have two scripts using almost identical code.
One of them works and finds the field (email) - the PRIMARY KEY (email)
and the other doesn't (user_key) - not indexed
Is this because PHP 7 needs to use only indexes in the WHERE part of SQL Query?
Here are the two scripts - first one works
$sql = 'SELECT access,fname FROM clients WHERE email=?';
$stmt = $connect->prepare($sql);
$stmt->execute([$email]);
$data_exists = ($stmt->fetchColumn() > 0) ? true : false;
if ($data_exists) { // account found.
$row = $stmt->fetch();
$access = $row['access'];
$fname = $row['fname'];
}
else {
$err_msg = 'Invalid Email Address and/or Password.';
$email = '';
$pass = '';
require_once ("login_fm.php");
exit;
}
[/PHP]
This second one drops through to the ERROR page.
$sql = 'SELECT email,fname,lname,confirm FROM clients WHERE user_key=?';
$stmt = $connect->prepare($sql);
$stmt->execute([$the_key]);
$data_exists = ($stmt->fetchColumn() > 0) ? true : false;
if ($data_exists) { // Account found.
$row = $stmt->fetch();
$email = $row['email'];
$name = $row['fname'].' '.$row['lname'];
$confirm = $row['confirm'];
$_SESSION['auth'] = "yes";
$_SESSION['email'] = $email;
$_SESSION['name'] = $name;
$sql = 'UPDATE clients SET confirm = ?,log_count = log_count+1,last_date=? WHERE email=?';
$stmt= $connect->prepare($sql);
$stmt->execute(['y',$today_time,$email]);
require_once("index.php"); // SUCCESSFUL LOGIN: THIS LOADS THE START PAGE
exit;
} // end if
else {
$err_page_message = "ERROR - Account not found $the_key : $name";
require_once("err.php");
exit;
} // end else
May be it's a different reason - like I'm too tied !
On the second one. I could rewrite it to just try the update and fail-over to the ERROR page,
But it would be nice to know why it isn't working.
It's quite simple, I just want to check to see if a row exists with the condition given, that's all.
I never had this problem the old mysql but the PDO seems a bit tricky or I'm just using the wrong code lol.
Thanks