(UPDATED)
I’m working on a personal project where the user’s data (user who log in) will be shown/fetch. When I run the PHP code, it does not give the error but also did not display or retrieve the data from the database, I dont know what part of the code is the problem. Should I need first declare the variables?
I also encounter an error that point the ’email’ in the query
Notice: Undefined variable: email
This is the code so you can check.
<?php
$query=mysqli_query($con,"SELECT * FROM tbl_account where email='$email' ");
while($result = mysqli_fetch_array($query))
{
$email = $result['email'];
echo " <div class='info-user'>";
echo " <div>";
echo " <label>Firstname:</label> <b>".$result['firstName']."</b>";
echo "</div> ";
echo "<hr /> ";
echo "<br /> ";
echo " <div>";
echo " <label>Lastname:</label> <b>".$result['lastName']."</b>";
echo "</div> ";
echo "<hr /> ";
echo "<br /> ";
echo " <div>";
echo " <label>Username:</label> <b>".$result['email']."</b>";
echo "</div> ";
echo "<hr /> ";
echo "<br /> ";
echo " <div>";
echo " <label>Username:</label> <b>".$result['sex']."</b>";
}
?>
EDIT. I already put the $email = $result['email'];above the query but it gave a new errors
Notice: Undefined variable: result
Notice: Trying to access array offset on value of type null
>Solution :
On this line:
$query=mysqli_query($con,"SELECT * FROM tbl_account where email='$email' ");
$email is a variable. This variable has not been defined. That is why you get the error.
When you do define it (hard code it, or get it from somewhere), the error will disappear.