-1

i am getting these errors:

Warning: mysql_query() expects parameter 1 to be string, object given in H:\xamp\htdocs\newlogintry.php on line 12

Warning: mysql_query() expects parameter 1 to be string, object given in H:\xamp\htdocs\newlogintry.php on line 13

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in H:\xamp\htdocs\newlogintry.php on line 18

but this is the php code I wrote for it, I want to check whether the "type" of account is either teacher account or is it a pupil account if any among them then pass to main page with respective type parameter, please tell me if my usage of php is right since i am new to it, here is the php code(newlogintry.php)

<?php
$start=1;
$username=$_GET['username'];
$password=$_GET['password'];

$con=mysqli_connect("localhost","root","","repute system");
    if(mysqli_connect_errno()){
        echo "ERROR ".mysqli_connect_error();
    } 
        //$result = mysqli_query($con,"SELECT password FROM accounts WHERE username=".$username);
    $result = mysqli_query($con,"SELECT password,username,type,u_name FROM accounts ");
    $new = mysql_query($con, "SELECT name,USN,repute,acc_type,u_name FROM pupil ");
    $new1= mysql_query($con,"SELECT name,id,repute,acc_type,u_name FROM teacher");    
     
        

        
      if(mysqli_num_rows($new)>0)
        {
         while($row = mysqli_fetch_assoc($new)) {
                
                $pupilaccount = $row['acc_type'];       
         

                if(mysqli_num_rows($new1)>0)
                 {
                       while($row = mysqli_fetch_assoc($new1)) {
                           $teacheraccount = $row['acc_type'];
                          

                            if(mysqli_num_rows($result)>0)
                             {
                                  while($row = mysqli_fetch_assoc($result)) {
        
       
                                        $pass=$row['password'];
                                        $use=$row['username'];
                                        $type=$row['type'];

                                        if( $type==$teacheraccount and $password == $pass and $username==$use){
                                                 header("location:http://localhost/index.php?param=$teacheraccount&param1=$username");  
                                          exit();
                                      }
                                      else if($type==$pupilaccount and $password == $pass and $username==$use)
                                      {
                                            header("location:http://localhost/index.php?param==$pupilaccount&param1=$username");   
                                            exit();   
                                      }
                                  }
                            }         
             }
        }
      }              
        
        
          
        }
      }




?>
Community
  • 1
  • 1
kernel
  • 11
  • 8
  • 4
    mysql_query != mysqli_query. Don't use any function that starts with mysql_. – Devon Bessemer Apr 22 '15 at 18:17
  • thanks @Devon after i changed that i am getting this error Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in H:\xamp\htdocs\newlogintry.php on line 31 – kernel Apr 22 '15 at 18:19
  • Update your code and errors in the question. – Devon Bessemer Apr 22 '15 at 18:20
  • @Chris i tried the link but it didn't help me out ! – kernel Apr 22 '15 at 18:28
  • A search for **"mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given"** on StackOverflow brings up 124 results. Did we seriously need to ask this question *again*? – spencer7593 Apr 22 '15 at 18:33
  • yes sorry for that @spencer7593 but i rectified that mistake and i am having a new one can you look at it once the warning is Catchable fatal error: Object of class mysqli_result could not be converted to string in H:\xamp\htdocs\newlogintry.php on line 12 – kernel Apr 22 '15 at 18:41
  • 1
    Dude you can't just keep updating the question with your new errors, thats not how SO works. Plus you didn't update the code along with it, so it makes no sense. Do some troubleshooting and Googling. – Dan Apr 22 '15 at 18:44
  • @dan08 i did update the code please look at it properly, as i said u i am new to php, so whats there in helping me? – kernel Apr 22 '15 at 18:46
  • 1
    @kernel, now that I placed an answer, you shouldn't change the question, you can add to it, but it seems like you need to learn what the error messages mean so you can debug it on your own. – Devon Bessemer Apr 22 '15 at 18:49
  • sorry if am disturbing you but this is quite important to me so @Devon – kernel Apr 22 '15 at 18:51
  • 3
    Edits have morphed the question from the original question, to a different question about a different error message, to no more errors but unexpected behavior... this post is really more request for debugging help, and not an actual question that can be answered. (An answer to the original question is already posted.) – spencer7593 Apr 22 '15 at 18:52
  • may be but, y not help me rather than, tell how the question has traversed from different states, its not INTENTIONAL, and i am learning quite a lot from you guys here, @spencer7593 – kernel Apr 22 '15 at 18:58
  • 2
    At this point, if you are trying to learn, I think it is important for you to research the specific error message so you can grasp what they mean and have a resource (teacher, friend, colleague) to reach out to for further assistance. If it is truly important, then you should consider paying for consultation with an experienced programmer. This is beyond the scope of Stackoverflow as a resource. – Devon Bessemer Apr 22 '15 at 19:01
  • @kernel: StackOverflow is designed and maintained as a site for Questions and Answers, not as a forum for posting an evolving request for debugging help. [**http://ericlippert.com/2014/03/05/how-to-debug-small-programs/**](http://ericlippert.com/2014/03/05/how-to-debug-small-programs/) – spencer7593 Apr 22 '15 at 19:06
  • thanks for the article @spencer7593 it really conveyed the thought into me, what you were trying to tell me earlier is also the same i agree. thanks – kernel Apr 22 '15 at 19:17
  • @kernel Please stop editing and changing your question, you're invalidating the answers being given to you. If you have another question, [ask](http://stackoverflow.com/questions/ask) – Madara's Ghost Apr 23 '15 at 06:55

1 Answers1

1

Error message:

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in H:\xamp\htdocs\newlogintry.php on line 31

Line 31 is:

                          if(mysqli_num_rows($result)>0)

This error means $result is not a mysqli_result which is what mysqli_num_rows expects, $result is most likely false which means the corresponding query failed.

$result is defined here:

  $result = mysqli_query($con,"SELECT password,username,type,u_name FROM accounts ");

You need to check if the query succeeded and if not, look for the error message. I recommend reading the manual on MySQLi at php.net.

Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95
  • Thanks i fixed up that up and this is the new warning i am having Catchable fatal error: Object of class mysqli_result could not be converted to string in H:\xamp\htdocs\newlogintry.php on line 12 – kernel Apr 22 '15 at 18:39