-2

I want to retrieve all data from a table, so I use this code

<?php
    include("config.php");
    $sql = "SELECT * FROM ".$USERS;
    $sql_result = mysqli_query($connection, $sql);
    if ($sql_result) {
      while ($result = mysql_fetch_assoc($sql_result)) {
         echo $result;
       }
    } 
    else {
       die ('Could not execute SQL query '.$sql);
    }
?>

but got this warning:

 Warning: mysql_fetch_assoc() expects parameter 1 to be resource,
 object given in C:\xampp\htdocs\newSDP\phpscript\users.php on line 6

How can I fix it?

1 Answers1

2

Change: mysql_fetch_assoc to mysqli_fetch_assoc

gabs
  • 87
  • 8
  • I agree with @arkascha. At least give Jon Stirling or Bhaskar credit for the answer. – Douwe de Haan Apr 04 '17 at 09:07
  • maybe @Bhaskar should have pasted it as an answer not a comment is he/she was sure. –  Apr 04 '17 at 09:09
  • Well no credit is needed here since it's too damn obvious why they get the error. That's why I also downvoted the question – Alon Eitan Apr 04 '17 at 09:10
  • Although the time stamp on Jon Stirlings comment says (currently) 17 minutes ago, and the timestamp on this answer says 16 minutes ago. So it looks like this answer came first.. Just saying... – superphonic Apr 04 '17 at 09:19
  • It is obvious to you does make it obvious to everyone, I am not a PHP developer, I use other languages with mongoDB, You see you are one of the reasons I don't care much if I get a down vote so far I get the ans I need. And tnks gabs for the ans it was what I needed, Plus @superphonic tnks for noting that. So everyone else pls before you show your self an asshole try to make sure you check the time stamp on the ans. Tnk u :-). –  Apr 04 '17 at 09:37