Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    140
    Thanks
    8
    Thanked 0 Times in 0 Posts

    mysql_query error() and mysql_fetch_array()

    PHP Code:
    <?php
    $host
    "localhost";
    $user"root";
    $pass"root";
    $db"login";


    $con=mysql_connect("$host","$user","$pass","$db");



    #line 71# $result = mysql_query($con,"SELECT * FROM users");

    #line 73# while($row = mysql_fetch_array($result))
      
    {
      echo 
    $row['id'] . " " $row['username'] . " " $row['password'];
      echo 
    "<br>";
      }

    mysql_close($con);

    ?>
    When I run my code, I'm getting the following error:


    Warning: mysql_query() expects parameter 1 to be string, resource given in C:\Users\Andrew McFarland\Xampp\htdocs\APP\index.php on line 71

    Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\Users\Andrew McFarland\Xampp\htdocs\APP\index.php on line 73

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,633
    Thanks
    0
    Thanked 649 Times in 639 Posts
    The calls are mysqli_ and you have left the "i" out of all of them.

    mysql_ was the old now obsolete and about to be removed interface where the parameters were the other way around.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Regular Coder
    Join Date
    Jul 2011
    Posts
    140
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    The calls are mysqli_ and you have left the "i" out of all of them.

    mysql_ was the old now obsolete and about to be removed interface where the parameters were the other way around.
    Thanks!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •