Reputation: 1111
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?
Upvotes: 0
Views: 354
Reputation: 17289
you should check result before fetch:
if ($res) {
while ($row = $res->fetch_array(MYSQLI_BOTH)) {
...
...
}
} else {
echo printf("Errormessage: %s\n", mysqli_error($mysqli));
}
Upvotes: 0
Reputation: 343
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
Upvotes: 1