0

I am receiving a "Fatal error" once the function fetch_array(mysqli_both) is invoked. The file below on the while instance is exactly where the error is coming from.

    <?php
include 'connect.php';
$id = $_SESSION['user_id'];
$res = mysqli_query($mysqli, "SELECT a.name,j.link,j.points, a.submit_time from journal j, article a where a.journal_id = j.id and a.professor_id = $id");
?>
<table>
    <tr>
        <th>Article</th>
        <th>Journal</th>
        <th>Points</th>
        <th>Time</th>
    </tr>
<?php
while ($row = $res->fetch_array(MYSQLI_BOTH)) {
?>
    <tr>
        <td><?php echo $row[0] ?></td>
        <td><?php echo $row[1] ?></td>
        <td><?php echo $row[2] ?></td>
        <td><?php $date = date_create($row[3]);
echo date_format($date, 'Y-m-d H:i:s'); ?></td>
    <tr>
<?php   
}
?>
</table>

When i try it on my wampserver i don't have this problem as i activated couple of PHP extensions. Online, i don't think it's easy to activate such extensions. Do you think this error is related to the fact that i didn't invoked the $query as a variable with $mysqli in line 4?

1
  • What $_SESSION['user_id'] contains? ... You should post the error info. Commented Feb 7, 2015 at 13:05

2 Answers 2

1

First of all you should use require_once('connect.php'); because it is a needed file for this code.

Also you have to check your $mysqli variable if it's a correct connection to your database.

For more help you might have to post the full Error-Message

Sign up to request clarification or add additional context in comments.

3 Comments

Fatal error: Call to a member function fetch_array() on a non-object in /homepages/journaltable.php on line 16
then you might have an error in your SQL-Syntax. Try to run it on phpmyadmin.
I think it has to be journal AS j and article AS a
0

you should check result before fetch:

if ($res) {
while ($row = $res->fetch_array(MYSQLI_BOTH)) {
...
...
}
} else {
echo printf("Errormessage: %s\n", mysqli_error($mysqli));
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.