eleatt Posted December 20, 2010 Share Posted December 20, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/222212-problem-of-view-blogs/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 20, 2010 Share Posted December 20, 2010 You need to select a database, either in your mysqli_connect() statement or using a mysqli_select_db() statement. Quote Link to comment https://forums.phpfreaks.com/topic/222212-problem-of-view-blogs/#findComment-1149535 Share on other sites More sharing options...
eleatt Posted December 20, 2010 Author Share Posted December 20, 2010 In which part of the code should that be? Before the echo? Quote Link to comment https://forums.phpfreaks.com/topic/222212-problem-of-view-blogs/#findComment-1149537 Share on other sites More sharing options...
PFMaBiSmAd Posted December 20, 2010 Share Posted December 20, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/222212-problem-of-view-blogs/#findComment-1149543 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.