I tried several times but cannot succeed in getting the right syntax—according to PHP 5.5.12 —to fetch single or multiple rows from my database.
session_start();
$con=mysqli_connect("localhost","root","","doortolearn");
if (!$con) {
echo "Could not connect to DBMS";
}
$query="select * from teacher where tremail='$_POST[email]' and trpasssword='$_POST[password]'";
$result=mysqli_query($con,$query);
$flag=FALSE;
while ($row=mysqli_fetch_array($result,MYSQLI_BOTH)) {
$_SESSION['email']=$row['email'];
$flag=TRUE;
}
can You try this code
First, you have no single quotes
'
around$_POST[password]
:But past that, do you even have a MySQL database connection set here? I see
$con
but is that really working?Also, check if there are errors by adding
or die(mysql_error($con))
to yourmysqli_query($con, $query)
line.Also, you have a
$_SESSION
value, but do you even setsession_start
at the beginning of your script?But I also recommend you use
mysqli_stmt_bind_param
for your values to at least escape them if you are not going to do basic validation: