Web Analytics Made Easy -
StatCounter PHP Issue - CodingForum

Announcement

Collapse
No announcement yet.

PHP Issue

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP Issue

    Getting the following error message which I can't resolve:

    mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\Users\Tim\Desktop\XAMP\htdocs\getuser.php on line 40

    The line of code it is on is as follows:

    <?php
    $q = intval($_GET['q']);

    $con = mysqli_connect('localhost','','');
    if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
    }

    mysqli_select_db($con,"testdb");
    $sql="SELECT * FROM records WHERE id = '".$q."'";
    $result = mysqli_query($con,$sql);

    echo "<table>
    <tr>
    <th>Forename</th>
    <th>Surname</th>
    <th>Age</th>
    <th>School</th>
    <th>Course</th>
    </tr>";
    while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['Forename'] . "</td>";
    echo "<td>" . $row['Surname'] . "</td>";
    echo "<td>" . $row['Age'] . "</td>";
    echo "<td>" . $row['School'] . "</td>";
    echo "<td>" . $row['Course'] . "</td>";
    echo "</tr>";
    }
    echo "</table>";
    mysqli_close($con);
    ?>

    Line 40 is: while($row = mysqli_fetch_array($result)) {

    HELP this has been driving me bonkers!

  • #2
    the usual issue ... your query fails.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

    Comment


    • #3
      Can you provide a solution?

      Comment


      • #4
        sure. add database error handling to your script.
        The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
        André Behrens, NY Times Software Developer

        Comment

        Working...
        X