-1

I m a begginer with PHP having started PHP 20 days before. I m trying with the latest version of PHP i.e. PHP 5.5.12 and MySQL i.e. MySQL 5.6.17. I m not being able to fetch data from the table. My php code is:

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'];
    mysqli_close($con);
    $flag=TRUE;
    header("location: http://localhost/dtlteacher/home.php");
}
if($flag){
    mysqli_close($con);
    header("location: http://localhost/dtlteacher/index.php?dr=1;");
}

Error is: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\dtlteacher\dblogin.php on line 10

Rahul Goel
  • 76
  • 1
  • 1
  • 8
  • please don't vote negative. it prevents me to ask future questions. I shall be thankful – Rahul Goel Jun 04 '14 at 06:23
  • 1
    Questions are downvoted on their merits. I'd guess in this case you're being downvoted because a simple Google search would have taken you to half a dozen questions on Stack Overflow that would have answered your question. Next time, search first. –  Jun 04 '14 at 06:37

1 Answers1

0

As a beginner programmer, you are making one mistake - failing to check for errors.

Run your query like this.

if (!mysqli_query($con,$query))
{
  echo("Error encountered: " . mysqli_error($con));
}
crafter
  • 6,121
  • 1
  • 32
  • 44