Hello again.
I have insert title, author and content data into table with admin-are page and now want to create a user-view-page.php that everybody enter into that page and see all posts one after an other, something like this model:
first title by first author
first content
seconr title by second author
second content
.
.
last title by last author
last content
This is my code but it doesn't work:
<?php
$servername = "localhost";
$dbname = "mydbname";
$dbusername = "mydbusername";
$dbpassword = "mydbpassword";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $dbusername, $dbpassword);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM Posts WHERE";
$result = $conn->query($sql);
foreach($result as $row) {
echo $result;
}
} catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
}
?>
<html>
<head>
<title>user view page</title>
</head>
<body>
<?php
echo $result;
?>
</body>
</html>
What changes this code needs? Where is the problem? With sql syntax or with php code?