Jump to content

Help! with displaying posts


elviapw

Recommended Posts

I'm new to PHP and i'm creating a password-protected blog. the only page that isn't working is the "posted.php" page, which posts the information after a user has logged in. the problem with the code is in query2, because the echo "yes", which I'm using to test the query, does not print. The page should print YES, YES, and then VIEW POST; it should also add the "post" and "title" to the archive (archive.php). I don't think I'm using the right function to add the information to the database. Help! here's the code:

 

<html>

<head>

<title>posted</title>

</head>

<body>

 

<table>

<thead>YES</thead>

<tbody>

 

<?php

$title = $_REQUEST["title"];

$post = $_REQUEST["post"];

 

 

 

 

$dbh = mysqli_connect("--", "--", "--", "--");

$sql = "INSERT INTO Posts

    (Number,Title,Content)

    VALUES(null,'$title', '$post');";

 

   

 

$query = mysqli_query($dbh,$sql);

 

$newpost = "SELECT Number,Title,Content FROM Posts ORDER BY Number DESC";

$query2 = mysqli_query($dbh,$newpost);

 

if($query2) {

 

echo "YES";

 

$feed = mysqli_fetch_assoc($query2);

$number = $feed['Number'];

$title = $feed['Title'];

$post = $feed['Content'];

 

echo"VIEW POST\n";

echo "</tbody>";

 

 

}

 

 

 

?>

</table>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/144413-help-with-displaying-posts/
Share on other sites

connect before this peice of code:

 

$title = $_REQUEST["title"];
$post = $_REQUEST["post"];

 

 

its not a long peice of code, but please remember to put it in code tags, ill display below

 

** actually tags do not include the "."

 

[code.][./code]

html>
<head>
<title>posted</title>
</head>
<body>

<table>
<thead>YES</thead>
<tbody>

<?php
$title = $_REQUEST["title"];
$post = $_REQUEST["post"];




$dbh = mysqli_connect("--", "--", "--", "--");
$sql = "INSERT INTO Posts
    (Number,Title,Content)
    VALUES(null,'$title', '$post');";
   
   

$query = mysqli_query($dbh,$sql);

$newpost = "SELECT Number,Title,Content FROM Posts ORDER BY Number DESC";
$query2 = mysqli_query($dbh,$newpost);

if($query2) {

echo "YES";

$feed = mysqli_fetch_assoc($query2);
$number = $feed['Number'];
$title = $feed['Title'];
$post = $feed['Content'];

echo"VIEW POST\n";
echo "</tbody>";


}



?>
</table>
</body>
</html>

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.