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

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.