Why did you decided to go why individual
bindParam
instead of one
execute
which does everything?
Also, I just found what was wrong with the previous code I gave you. It should be the other way around :
if($check = $sql->fetchObject())
{
session_start();
$_SESSION['login'] = 1;
$_SESSION['email'] = $_POST['email'];
header("Location: home.php");
}
else
{
header("Location: signin.php");
}
instead of
if($check = $sql->fetchObject())
{
header("Location: signin.php");
}
else
{
session_start();
$_SESSION['login'] = 1;
$_SESSION['email'] = $_POST["email"];
header("Location: home.php");
}
This is because, in your code,
if ($count == 1)
is equal to
if($count == true)
or simply
if($count)
. This is also what
if($check = $sql->fetchObject())
does, except it doesn't rely on the numericallity of a value, and for this reason is better in my opinion.
I also imagine that simply performing a
fetchObject
would be easier/quicker than a
rowCount
.
If others have anything to say, it would help me
_____________________________________________________________________________________
Edit : Try this :
<?php
try
{
$conn = new PDO('mysql:dbname=users;host=localhost', 'register', 'mysql');
echo 'Successful Connection';
}
catch(PDOException $e)
{
echo $e->getMessage();
}
$sql = $conn->prepare('SELECT * FROM users WHERE Password = :password AND Email = :email');
$sql->execute(array('password' => $password, 'email' => $email));
if($check = $sql->fetchObject())
{
session_start();
$_SESSION['login'] = 1;
$_SESSION['email'] = $_POST['email'];
header('Location: home.php');
}
else
{
header('Location: signin.php');
}
?>
And I just saw something. Do
NOT select all fields (*) when you do perform a
SELECT
, especially not if you only want to make sure the user is existing. Just select one, even if you don't have any use for it.
Also, notice that I've replaced basically every
"
for a
'
.