Jump to content

Receiving Errors In My Php Code :(


Kirk

Recommended Posts

Hi there everyone,

 

I'm getting errors in my php application i'm making.

 

Here's my errors i'm getting

 

Error

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/w0638385/public_html/blog/index.php on line 9

 

 

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/w0638385/public_html/blog/index.php on line 22 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/w0638385/public_html/blog/index.php on line 29

 

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/w0638385/public_html/blog/index.php on line 41

 

 

Here's my code:

 

<?php

require("header.php");

$sql= "SELECT entries.*, categories.cat FROM entries, categories WHERE entries.cat_id = categories.id ORDER BY dateposted DESC LIMIT 1;";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
echo "<h2 id='title'> <a href='viewentry.php?id=" .$row['id']. "'>" . $row['subject'] . "</a></h2><br />";
echo "<p id='byline'>In <a href='viewcat.php?id=" .$row['cat_id'] . "'>" . $row['cat'] . "</a> - Posted on<span class='datetime'>" . date("D jS F Y g.iA",strtotime($row['dateposted'])) . "</span></p>";
echo "<p>";
echo nl2br($row['$body']);
echo "</p>";

// Comments on this blog entry:

echo "<p id='coments'>";

$commsql = "SELECT name FROM comments WHERE blog_id =" . $row['id'] . " ORDER BY dateposted;";
$commresult = mysqli_query($db, $commsql);
$numrows_comm = mysqli_num_rows($commresult);

// Begin If statement
if ($numrows_comm === 0) {
echo "(<strong>" .$numrows_comm . "</<strong>) comments : ";
$i = 1;
}else{
while ($commrow = mysqli_fetch_array($commresult, MYSQLI_ASSOC)) {
echo "<a href='viewentry.php?=" . $row['id'] ."#comment" . $i . "'>" .$commrow['name'] . "</a>";

$i++;
}
}
echo "</p>";

// Display the previous 5 blog entries:

$prevsql = "SELECT entries.* ,categories.cat FROM entries, categories WHERE entries.cat_id = categories.id ORDER BY dateposted DESC LIMIT 1, 5;";
$prevresult = mysqli_query($db, $prevsql);
$numrows_prev = mysqli_num_rows($prevresult);

echo "<div id='prev'>";
if($numrows_prev == 0) {
echo "<p>No previous entries.</p>";
}
else{
echo "<ul>";
while ($prevrow = mysqli_fetch_array($prevresult, MYSQLI_ASSOC)) {
echo "<li> <a href='viewentry.php?id=" . $prevrow['id'] . "'>" . $prevrow['subject'] ."</a></li>";
}
echo "</ul>";
}
echo "</div>";

require("footer.php");
?>

Could anyone please tell me what I did wrong? Thank you in advanced!

Link to comment
Share on other sites

Problem must be in your sql query.. Try with printing a debugging message after query execution. You can do it something like this...

 

// Debugging message:
echo '<p>' . mysqli_error($db) . '<br /><br />Query: ' . $sql . '</p>';

 

This will print your query and its errors

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.