Hi there guys thanks for taking the time to give me a hand, I am struggling with two issues really but one can do for now. Basically I'm creating a blog connecting to my database MYSQL. The issue is the first error this..
Warning: mysql_query() expects parameter 1 to be string, resource given in D:\xampp\htdocs\wd1_osmanovic_0100348514\pages\blog.php on line 19
What I am trying to achieve is I can have as many blogs and when a user click continue reading this blog, the other blogs will just dissapear as they have different page id's but it's not working. What I've done ti fix the error is add ($sql, connection). But I could be wrong? My code on that page..
<?php
//--- Authenticate code begins here ---
session_start();
//checks if the login session is true
if(!isset($_SESSION['username'])){
header("location:index.php");
}
$username = $_SESSION['username'];
// --- Authenticate code ends here ---
include ('header.php');
function displayAllBlog(){
global $connection;
$sql = "SELECT * FROM blog"; //SQL query
$result = mysql_query($connection) or die(mysql_error($connection)); //run the query
while($row = mysql_fetch_array($result)){ //use a while loop to display all the rows in the database
echo "<h1>" . $row['blogTitle'] . "</h1>";
echo "<h3>" . $row['dateTime'] . " " . $row['authorID'] . " " . $row['catID'] . "</h3>";
echo "<p>" . $row['blogContent'] . "</p>";
echo "<p>" . (substr(($row['authorID']),0,100)) . "</p>";
echo "<a href='blog.php?id=" .$row['blogID']. "'>Go to blog.</a>";
}
}
?>
<link rel="stylesheet" type="text/css" href="../css/style1.css">
<div style="float:right"> <a class="btn btn-danger logout" href="logout.php" > Logout</a> </div>
<div id="menu">
<ul id="nav">
<li><a href="home.php" target="_self" >Home</a></li>
<li><a href="session1.php" target="_self" >Sessions</a>
<ul>
<li><a href="session1.php" target="_self" >Session 1</a></li>
<li><a href="session2.php" target="_self" >Session 2</a></li>
<li><a href="session3.php" target="_self" >Session 3</a></li>
<li><a href="session4.php" target="_self" >Session 4</a></li>
<li><a href="session5.php" target="_self" >Session 5</a></li>
<li><a href="session6.php" target="_self" >Session 6</a></li>
<li><a href="session7.php" target="_self" >Session 7</a></li>
<li><a href="session8.php" target="_self" >Session 8</a></li>
<li><a href="session9.php" target="_self" >Session 9</a></li>
<li><a href="session10.php" target="_self" >Session 10</a></li>
<li><a href="session11.php" target="_self" >Session 11</a></li>
<li><a href="session12.php" target="_self" >Session 12</a></li>
<li><a href="session13.php" target="_self" >Session 13</a></li>
<li><a href="session14.php" target="_self" >Session 14</a></li>
</ul>
<li><a href="blog.php" target="_self" >Blog</a></li>
</ul>
</div>
<?php
$blogID = 0;
if(!empty($_GET['ID']))$blogID = mysql_real_escape_string($connection, $_GET['ID']); //Grabs blog ID from get
if($blogID >= 1){
//echo blog based on ID, else fall back on displaying all.
$sql = "SELECT * FROM blog WHERE blogID='$blogID'"; //SQL query
$result = mysql_query($sql, $connection) or die(mysql_error($connection)); //run the query
$count = mysql_num_rows($result); //Number of rows
if($count == 1){
//Echo Single blog
$row = mysql_fetch_array($result);
echo "<h1>" . $row['blogTitle'] . "</h1>";
echo "<h3>" . $row['dateTime'] . " " . $row['authorID'] . " " . $row['catID'] . "</h3>";
echo "<p>" . $row['blogContent'] . "</p>";
echo "<p>" . (substr(($row['authorID']),0,100)) . "</p>";
}else{
//IF NO BLOG MATCHES WITH ID GIVEN, DISPLAY ALL
displayAllBlog();
}
}else{
//IF NO $GET DISPLAY ALL
displayAllBlog();
}
?>
<?php include ('footer.php'); ?>
THANKS A LOT :)!