Jump to content

problem of view blogs


eleatt

Recommended Posts

Im trying to make this news blog for my assignment. When user selects a certain blog the blog id is stored in the veriable $blogid. I am using the SELECT FROM WHERE but something is going wrong cos it keeps telling me :Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in F:\xampp\htdocs\Blog\viewBlog.php on line 12. What is the problem and what do i have to change?? This problem is in the second page the View blog page.

 

this is my code:

 

View all page:

 

<html>

<body>

<?php

$dbc = mysqli_connect('localhost','root','','blogdb')

or die ('Error: Could not connect to database. Please try again');

$query = "SELECT title, postdatetime, username FROM blog";

 

//echo "$query";

 

$result = mysqli_query($dbc, $query);

 

/*echo"<table border=1>";

echo "<tr>

<th> Title</th>

<th> Postdatetime</th>

<th> Posted by :</th>

</tr>"; */

while($row = mysqli_fetch_array($result))

{

$Title = $row ['title'];

$PostDateTime = $row ['postdatetime'];

$Username=$row['username'];

 

$url= "viewBlog.php?blogid=".$blogid;

echo "<a href = $url> $Title $PostDateTime</a></br>";

 

}

 

mysqli_close($dbc);

?>

</body>

</html>

 

View Blog page :

<?php

$blogid= $_GET ['blogid'];

 

$dbc = mysqli_connect('localhost','root','','blogdb')

or die ('Error: Could not connect to database. Please try again');

 

$query = ("SELECT * FROM blogs WHERE blodid = '$blogid'");

 

 

$result = mysqli_query($dbc, $query);

 

while($row = mysql_fetch_array($result))

{

$Title = $row ['title'];

$Content = $roe ['content'];

 

echo "$Title $Content";

}

 

mysqli_close($dbc);

 

?>

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/222212-problem-of-view-blogs/
Share on other sites

Actually, I miss read your mysqli_connect(), you are not using a password, but you are listing the database name.

 

The error in your viewBlog.php code is most likely because you are mixing mysqli_ and mysql_ statements and/or it could be because your table name is not blogs and the query is failing.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.