0
    <?php
session_start();
$message ="";
$connect = mysqli_connect("localhost", "root","", "testdb");

if(isset($_POST['login']))
{

if(empty($_POST["email"]) && empty($_POST["password"]))  
      {  
           echo '<script>alert("Both Fields are required")</script>';  
      }  
      else  
      {  
           $uemail = mysqli_real_escape_string($connect, $_POST["email"]);  
           $upassword = mysqli_real_escape_string($connect, $_POST["password"]);  
           $upassword = md5($upassword);  
           $query = "SELECT * FROM users1 WHERE email = '$uemail' AND password = '$upassword'";  
           $result = mysqli_query($connect, $query);  
          $count=mysql_num_rows($result) ;
          if($count=1)
          {
              $role= mysql_fetch_array($result);
              if($role == "admin")
              {
                  header("location: index2.php");
                  exit();
              }
              elseif($role == "user")
            {
              header("location: index3.php");
              exit();
              }
          }
          else
          {
              echo "wrong email and password";
          }
      } 

 }   ?>

I am trying to redirect the login.php to different pages according to the role.

I have role as enum i.e 'admin','user' unfortunately i am getting this error.. I have even checked the $query.

It has no syntax errors.. but it is unable to fetch the data to $role.

Warning: mysql_num_rows() expects parameter 1 to be resource, object given in /Applications/XAMPP/xamppfiles/htdocs/p51/login.php on line 20 wrong email and password

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • You are mixing `MySQL` and `MySQLi`. I **assume** you mean `mysqli_num_rows()` (and `mysqli_fetch_array()`). – Obsidian Age Mar 22 '17 at 19:47
  • ohh got it! but when i click login.. it doesn't redirect.. is there any error because i used if-else condition? @ObsidianAge – Kishore Shyam Mar 22 '17 at 19:51
  • @KishoreShyam this you must fix `if($role == "admin")` you must use `if($role['role'] == "admin")` only if yours database table column contains 'role' or something else then change that. So if u have table column named 'role' and there u have value 'admin' then u use a code like i gave you or change 'role' to your name of table column. Same for others. – Mario Mar 22 '17 at 19:57
  • 1
    ohh that just worked perfectly...Thanks!! @Mario – Kishore Shyam Mar 22 '17 at 20:00
  • you don't plan on going live with this, are you? – Funk Forty Niner Mar 22 '17 at 20:23
  • @Fred-ii- no sir, it is just a college assignment .. just in the phase of learning! – Kishore Shyam Apr 11 '17 at 16:06

0 Answers0