-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;

    }
2
  • 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 Commented Sep 23, 2015 at 9:20
  • The now deprecated mysql_query method returns false on failure. So your code should be if($result && mysql_num_rows($result)) Commented Sep 23, 2015 at 9:39

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.