What's new

Content no display

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,166
Solutions
2
Reaction
103
Points
496
Age
30
kapag nbag cre-create ako bagong content sa thread.php is wala sya ouput o display kahit ireload ko pa o irefresh wala tlga sya display pero kapag bumalik ako sa title.php nandun na po yun content ko..

ito po code ko ng thread.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Homepage</title>
<link rel= "stylesheet" href="../css/bootstrap.css">
<link rel= "stylesheet" href="../css/style.css">
<script src="../js/bootstrap.bundle.js"></script>
<script src="../js/style.js"></script>
<script src="../ajax/sweetalert2.all.min.js"></script>
<script src="../ajax/jquery-3.7.0.min.js"></script>

</head>
<body>
<div class="container col-md-6">
<div class="mb-5 text-center">
<h1>Discussion Thread</h1>
</div>
<form method="POST" action="home.php">
<div class="input-group mb-2">
<span class="input-group-text fw-bold" id="basic-addon1">TITLE</span>
<input type="text" name="postcontent" class="form-control" placeholder="Please enter the title of your discussion here." aria-label="Username" aria-describedby="basic-addon1">
</div>
<label class="fw-bold mb-2" for="w3review">Content:</label>
<textarea name="post_content" class="form-control" id="post" rows="10" cols="50" placeholder="Your Content....."></textarea>
<div class="form-group mb-5 mt-2" style="text-align: right">
<input type="submit" name="post" class="w-25" value="Post" style="background-color:#0D52C7;">
<!-- <input class="col-md-3" type="submit" value="Post" style="background:#42A5F5";> -->
</div>
</div>
</form>

</body>
</html>

ito naman sa home.php o display ng content..

<!DOCTYPE html>
<html>
<head>
<title>POST AND COMMENT SYSTEM</title>
<?php include('dbconn.php'); ?>
<?php include('session.php'); ?>

<script src="vendors/jquery-1.7.2.min.js"></script>
<script src="vendors/bootstrap.js"></script>

</head>
<body>
<div id="container">
<br>
WELCOME!
<a href="title.php"><button><?php
echo $member_row['firstname']." ".$member_row['lastname'];
?> - Log Out</button></a>

<br>
<br>
<br>
WELCOME!
<a href="thread.php"><button><?php
echo $member_row['firstname']." ".$member_row['lastname'];
?> - thread</button></a>

<br>
<?php

?>
<?php
if(isset($_GET['id'])){
$id = $_GET['id'];
$query = mysqli_query($conn,"SELECT *,UNIX_TIMESTAMP() - date_created AS TimeSpent from post LEFT JOIN user on user.user_id = post.user_id WHERE post_id = '$id' order by post_id DESC limit 1")or die(mysqli_error());
while($post_row=mysqli_fetch_array($query)){
$id = $post_row['post_id'];
$upid = $post_row['user_id'];
$posted_by = $post_row['firstname']." ".$post_row['lastname'];
?>


<a style="text-decoration:none; float:right;" href="deletepost.php<?php echo '?id='.$id; ?>"><button><font color="red">x</button></font></a>
<h3>Posted by: <a href="#"> <?php echo $posted_by; ?></a>
-
<?php
$days = floor($post_row['TimeSpent'] / (60 * 60 * 24));
$remainder = $post_row['TimeSpent'] % (60 * 60 * 24);
$hours = floor($remainder / (60 * 60));
$remainder = $remainder % (60 * 60);
$minutes = floor($remainder / 60);
$seconds = $remainder % 60;
if($days > 0)
echo date('F d, Y - H:i:sa', $post_row['date_created']);
elseif($days == 0 && $hours == 0 && $minutes == 0)
echo "A few seconds ago";
elseif($days == 0 && $hours == 0)
echo $minutes.' minutes ago';
?>
<br>
<br><?php echo $post_row['content']; ?></h3>
<form method="post">
<hr>
Comment:<br>
<input type="hidden" name="id" value="<?php echo $id; ?>">
<textarea name="comment_content" rows="2" cols="44" style="" placeholder=".........Type your comment here........" required></textarea><br>
<input type="submit" name="comment">
</form>

</br>

<?php
$comment_query = mysqli_query($conn,"SELECT * ,UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment LEFT JOIN user on user.user_id = comment.user_id where post_id = '$id'") or die (mysqli_error());
while ($comment_row=mysqli_fetch_array($comment_query)){
$comment_id = $comment_row['comment_id'];
$comment_by = $comment_row['firstname']." ". $comment_row['lastname'];
?>
<br><a href="#"><?php echo $comment_by; ?></a> - <?php echo $comment_row['content']; ?>
<br>
<?php
$days = floor($comment_row['TimeSpent'] / (60 * 60 * 24));
$remainder = $comment_row['TimeSpent'] % (60 * 60 * 24);
$hours = floor($remainder / (60 * 60));
$remainder = $remainder % (60 * 60);
$minutes = floor($remainder / 60);
$seconds = $remainder % 60;
if($days > 0)
echo date('F d, Y - H:i:sa', $comment_row['date_posted']);
elseif($days == 0 && $hours == 0 && $minutes == 0)
echo "A few seconds ago";
elseif($days == 0 && $hours == 0)
echo $minutes.' minutes ago';
?>
<br>
<?php
}
}}?>
<hr



<?php
if (isset($_POST['post'])){
$post_content = $_POST['post_content'];

mysqli_query($conn,"insert into post (content,date_created,user_id) values ('$post_content','".strtotime(date("Y-m-d h:i:sa"))."','$user_id') ")or die(mysqli_error());
header('location:home.php');
}
?>
<?php

if (isset($_POST['comment'])){
$comment_content = $_POST['comment_content'];
$post_id=$_POST['id'];

mysqli_query($conn,"insert into comment (content,date_posted,user_id,post_id) values ('$comment_content','".strtotime(date("Y-m-d h:i:sa"))."','$user_id','$post_id')") or die (mysqli_error());
header('location: ' . $_SERVER['PHP_SELF'] . '?id=' . $post_id);
}
?>
</body>
<?php include('footer.php');?>
</html>
 
Based on the code you provided, it seems that the issue may lie in the form action attribute in the thread.php file. Currently, the form action is set to "home.php", which means that when the form is submitted, the data will be sent to the home.php file for processing. If you want the form data to be processed in the same file (thread.php) and display the output there, you need to set the form action attribute to an empty string or to the current page using PHP's $_SERVER['PHP_SELF'] variable.

Here's how you can modify the form tag in thread.php:

Code:
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">

By doing this, the form data will be submitted to the same page (thread.php), and you can handle the processing and display of the content in the same file.

Additionally, make sure that the code responsible for displaying the content is placed in the appropriate section of the thread.php file. It seems that the code for displaying the content is located after the closing </form> tag. Move this code to a location where it will be displayed on the page, such as after the closing </body> tag.

Once you make these changes, the newly created content should be displayed on the thread.php page after submitting the form.
 
Based on the code you provided, it seems that the issue may lie in the form action attribute in the thread.php file. Currently, the form action is set to "home.php", which means that when the form is submitted, the data will be sent to the home.php file for processing. If you want the form data to be processed in the same file (thread.php) and display the output there, you need to set the form action attribute to an empty string or to the current page using PHP's $_SERVER['PHP_SELF'] variable.

Here's how you can modify the form tag in thread.php:

Code:
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">

By doing this, the form data will be submitted to the same page (thread.php), and you can handle the processing and display of the content in the same file.

Additionally, make sure that the code responsible for displaying the content is placed in the appropriate section of the thread.php file. It seems that the code for displaying the content is located after the closing </form> tag. Move this code to a location where it will be displayed on the page, such as after the closing </body> tag.

Once you make these changes, the newly created content should be displayed on the thread.php page after submitting the form.
no display pa rin
 
no display pa rin
If the content is still not displaying after making the suggested changes, there could be other factors affecting the display. Here are a few troubleshooting steps you can try:

1. Check for any errors: Make sure error reporting is enabled in your PHP configuration by adding the following line at the beginning of your PHP files:
Code:
error_reporting(E_ALL);
This will help you identify any syntax errors or other issues that might be preventing the content from being displayed.

2. Verify the database connection: Ensure that the database connection is correctly established in the dbconn.php file. Check the database credentials and make sure they are correct.

3. Check the data insertion: After submitting the form, verify that the data is actually being inserted into the database by inspecting the database table. Confirm that the data is being stored correctly.

4. Check the query for displaying content: Verify that the query for retrieving and displaying the content is correct. Make sure the SQL query is retrieving the data from the correct table and using the appropriate conditions.

5. Debug the display code: Place some debugging statements in the code to check if the code for displaying the content is being executed. You can use echo or var_dump statements to print out variables and values at different points in the code to see if they are as expected.

6. Clear cache and cøøkíés: Sometimes, issues with the display can be caused by cached data. Clear your browser cache and cøøkíés, and try accessing the page again.

By following these troubleshooting steps, you should be able to identify and resolve the issue preventing the content from being displayed in your thread.php file.
 

Similar threads

Back
Top