-1

I am trying to send userid and otp which is entered in an edittext in an android app but from server side i get following response.

mysql_num_rows() expects parameter 1 to be resource, boolean given in /nfs/c07/h02/mnt/111018/domains/surun.co/html/demo/rest/api.php on line 168

line no 168 from php code

if(mysql_num_rows($results) > 0)

The php code in more details follows:

 public function selectQuery($table_name,$fields,$where="",$show = 0)

    {

       $i =0;

       if($where == "")

       $sql = "SELECT  ".$fields." FROM ".$table_name;

       else

       $sql = "SELECT  ".$fields." FROM ".$table_name." WHERE ".$where;

      //MySqli Select Query

      if($show == 1)

      return $sql;

      $results = mysql_query( $sql,$this->db );

      if(mysql_num_rows($results) > 0)

      {

        while($row = mysql_fetch_assoc($results))

        {

          $result[$i++]= $row;

        }

      }

      return $result;

    }
e4c5
  • 52,766
  • 11
  • 101
  • 134
  • I am not getting where the error or problem.actually these php is written by my friend so i am not able to slove the problem.please help – abhi jaghari Sep 23 '15 at 09:20
  • The now deprecated mysql_query method returns false on failure. So your code should be if($result && mysql_num_rows($result)) – e4c5 Sep 23 '15 at 09:39

1 Answers1

0

Read this link and apply these changes How could I change this mysql to mysqli? while also adding error checking in the form of

 $results = mysqli_query($this->db, $sql) or die (mysqli_error($connection));

(or for MySQL just use $results = mysqli_query($sql,$this->db) or die (mysql_error()); )

What you currently have is that your $this->db value is not connecting the database properly or you have a syntax error in your WHERE clause.

Community
  • 1
  • 1
Martin
  • 22,212
  • 11
  • 70
  • 132