CrazyEngineers
  • How to fetch data from existing table using PHP while I'm using XAMPP

    SatyaPHP

    SatyaPHP

    @satyaphp-ZcEgdV
    Updated: Oct 25, 2024
    Views: 959
    Hi The_Big_k,

    I'm fresher in PHP and I want to learn PHP very well..............Please help.........

    I'm facing problem to fetch data from my existing table using below code:

    mysql_select_db("my_db",$con);
     
    $result = mysql_query("SELECT * FROM Persons");
     
     
    while($row = mysql_fetch_array($result))
    {
    echo $row['FirstName'] . " " . $row['LastName'];
    echo "<br/>";
    }
     
    mysql_free_result($result);
    
    And the Browser displayed the below error message


    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\learn\selectData.php on line 25
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Whats In Name

    MemberFeb 3, 2013

    The warning you are getting shows that the query you tried to execute is facing some error and thus $result variable is storing FALSE and mysql_fetch_array() is getting a boolean as a parameter.To check for the error in query,use mysql_error() and tell us what browser displays.
    Are you sure? This action cannot be undone.
    Cancel
  • Prasad Ajinkya

    MemberFeb 4, 2013

    I think your table might not have any rows, hence the boolean variable being returned (false).

    Typically before running the mysql_fetch_array() method, always check with mysql_num_rows($result) > 0 condition.
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberFeb 16, 2013

    This error will only come if sql query is not proper

    Is the table named Persons exists in DB?
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register