12

I am getting the above warning when I try to run this code:

$mysqli=new mysqli("localhost", "***", "***","***") or die(mysql_error());


              function checklogin($username, $password){
                global $mysqli;


                $result = $mysqli->prepare("SELECT * FROM users WHERE username = ?");
                $result->bind_param("s", $username);
                $result->execute();

            if($result != false){

                $dbArray=mysql_fetch_array($result);
peterh
  • 11,875
  • 18
  • 85
  • 108
Sam Gabriel
  • 327
  • 1
  • 6
  • 15

3 Answers3

44

You are mixing mysql and mysqli calls in your code. Use mysqli_fetch_array instead of mysql_fetch_array.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Chandu
  • 81,493
  • 19
  • 133
  • 134
8

You are mixing mysqli and traditional mysql commands.

Use $result->fetch_array().

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • The first line should also use $mysqli->connect_error, not mysql_error(). – David Powers Jan 08 '11 at 17:09
  • But now I get : Fatal error: Call to undefined method mysqli_stmt::fetch_array() in /var/www/JMToday/loginchk.php on line 52 – Sam Gabriel Jan 08 '11 at 17:10
  • @Sam you need to use `query()` instead of `execute()`, that returns a result object that contains the `fetch_array` method. See here for a full example: http://php.net/manual/en/mysqli.query.php – Pekka Jan 08 '11 at 17:41
1

You're using two different sets of functions... mysqli and mysql.
I think you want to use the fetch_assoc() method.

Check out http://php.net/manual/en/book.mysqli.php

Nabab
  • 2,608
  • 1
  • 19
  • 32