I have a very simple login system for a web-app we use internally at my workplace. Doing some fixing, I'm trying to make the code less vulnerable by using msqli->prepare everywhere I can. For some reason, on the login code, this results in complete failure. Here's the old code:
$email = $_POST['email'];
$upass = $_POST['pass'];
$stmt = $sqlCon->query("SELECT * FROM users WHERE email='$email'");
$row = mysqli_fetch_array($stmt);
$stmt->close();
echo $row['password']; //this is just for debug!
This works great. It checks the users email against the table 'users' and returns the resulting array just perfect.
So, I tried to replace it with a prepare statement:
$email = $_POST['email'];
$upass = $_POST['pass'];
$sql = "SELECT * FROM users WHERE email='?'";
$stmt = $sqlCon->prepare($sql);
$stmt->bind_param('s', $email);
$stmt->execute();
$row = mysqli_fetch_array($stmt);
$stmt->close();
echo $row['password']; //this is just for debug!
I've tried the prepare statement with and without the '' around the ? and neither works. I get an error on mysqli_fetch_array() that it expects a myqsli_result and instead got an object... which seems to imply that the query returned nothing?
Obviously, I don't understand how something works, so any help would be great.