I perform a SELECT
to find out if there is a user with an email and password using the PHP prepared statements (Prepared Statement).
The problem is that after verifying that it does exist, I need to get the SSID of that user to put it in su $_SESSION
, and for that I need to do something similar to MySQLi Fetch Assoc
but that works in my case , which uses prepared statements.
My code:
// Preparar el SELECT
$stmt = $conn->prepare("SELECT * FROM tab_users WHERE email = ? AND pass = ?");
$stmt->bind_param("ss", $email, $mdpass);
// Ejecutar el SELECT y comprobar
$stmt->execute();
if ($stmt->num_rows >= "1") {
//Si hay 1 registro, recoger los datos aquí (es lo que necesito)
} else {
array_push($errors, "Correo electrónico o contraseña incorrectos");
}
// Cerrar las conexiones
$stmt->close();
$conn->close();
With
get_result()
you get the values of a prepared statement and later with the methodfetch_assoc()
you return the data set in an associative arrayLater with the use of
num_rows < 1
verifies that if there are no records a message is sentnow with a while loop, you loop through the values and retrieve them by their key or column name like so