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

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.