This is a small problem but I have been spending hours trying to figure out why it doesn't work.
I am trying to get firstname
or lastname
from the mysql database using the following code:
<?php
include "config/connect.php";
$manager = 'myemail@yahoo.co.uk';
$stmt = mysqli_prepare(
$db_conx,
"SELECT lastname
FROM members
WHERE email = ?
AND lastname = ?");
//after validation, of course
mysqli_stmt_bind_param($stmt, "ss", $manager, $lastname);
mysqli_stmt_execute($stmt);
print $lastname;
if (mysqli_affected_rows($db_conx))
{
mysqli_stmt_close($stmt);//<-- CLEAN UP AFTER YOURSELF!
$id = mysqli_insert_id($db_conx);
}
?>
for some strange reason it just doesn't print the lastname
or the lastname
at all. but if I print manager
, it prints it out properly.
what am I doing wrong?
P.S. i know the email
, firstname
and lastname
all exist in the database.
EDIT:
include "config/connect.php";
$manager = 'MYEMAIL@yahoo.co.uk';
$stmt = $db_conx->prepare("SELECT email, firstname
FROM members
WHERE email = ?
AND firstname = ?");
$stmt->bind_param('ss', $manager, $firstname);
$stmt->execute();
$stmt->bind_result($manager, $firstname);
$stmt->store_result();
if($stmt->num_rows == 1) //To check if the row exists
{
while($stmt->fetch()) //fetching the contents of the row
{
$firstname = $firstname;
$manager = $manager;
}
}
$stmt->close();