What's new

Pls help me phc robot

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,168
Solutions
2
Reaction
103
Points
497
Age
30
bat po kapag pinipindot ko yun title nun content di lumalabas yun sarili nya content po iisa content lang po lumalabas lahat po ng tile na magkakaiba iba iisa content lang lumalabas

ito code ko sa title.php
<?php
$sql = mysqli_query($con, "SELECT * ,UNIX_TIMESTAMP() - date_created AS TimeSpent FROM post left join registration on registration.user_id = post.user_id order by date_created DESC" ) or die (mysqli_error());
while($post_row = mysqli_fetch_array($sql)){
$id = $post_row['comment_id'];
$id_user = $post_row['username'];
$id_comment = $post_row ['comment_id'];
?>
</div>
<div class ="container col-md-6 bg-body-tertiary">
<a href="comment.php?id=<?php echo $id_comment;?>"><?php echo $post_row['title']; }?></a>

ito naman sa output comment.php
<?php
ob_start();
include "../partials/newnav.php";
if(isset($_GET['id'])){
$id_comment = $_GET['id'];
// Query to fetch the specific content based on the comment_id
$content_query = mysqli_query($con, "SELECT * FROM post WHERE comment_id = '$id_comment'") or die(mysqli_error());
$content_row = mysqli_fetch_array($content_query);
}
?>
<!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 text-center">
<br>
<h1>WELCOME To My Thread!</h1>

<br>



<br>
</div>
<?php
if (isset($_POST['post'])){
$page_content = mysqli_real_escape_string($con,$_POST ['post_content']);
$pagecontent = mysqli_real_escape_string($con,$_POST ['postcontent']);



mysqli_query($con,"INSERT INTO post (comment,title,date_created,user_id) values ('$page_content','$pagecontent','".strtotime(date("Y-m-d h:i:sa"))."','$user_id') ")or die(mysqli_error());

}
?>
<?php
$post_query = mysqli_query($con, "SELECT *, UNIX_TIMESTAMP() - date_created AS TimeSpent FROM post LEFT JOIN registration on registration.user_id = post.user_id ORDER BY comment_id DESC limit 1 ") or die (mysqli_error());
while($post_row = mysqli_fetch_array($post_query)){
$id = $post_row['comment_id'];
$upid = $post_row['user_id'];
$posted_by = $post_row['username'];
?>
<div class="container col-md-6 bg-body-tertiary border rounded-3" >
<a style="text-decoration:none; float:left;" href="deletepost.php<?php echo '?id='.$id; ?>">
<div class="pt-3">
Posted by: <a href="#" style= "margin-left:10px; text-decoration:none;"> <?php echo $posted_by; ?></a>
<div class="" style="font-size:12px;">
<?php
$current_time = time(); // Get the current time
$time_elapsed = $current_time - $post_row['date_created']; // Calculate the time elapsed in seconds
$days = floor($time_elapsed / (60*60*24));
$remainder = $time_elapsed % (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 ($time_elapsed < 60) {
echo "A few seconds ago";
} elseif ($time_elapsed < 3600) { // Less than 1 hour
echo $minutes . ' minutes ago';
} else {
// Handle other cases, such as hours, days, etc.
}
?>
</div>
<br>
<h6><?php echo $post_row['comment']; ?></h6>

</div>
</div>
<br>
<form method="post">

<div class="container col-md-6">
Comment:<br>
<input type="hidden" name="id" value="<?php echo $id; ?>">
<textarea name="comment_content" class="form-control" rows="4" cols="50" style="" placeholder=".........Type your comment here........" required></textarea>
<div class="form-group mt-2">
<input class="w-25" type="submit" name="comment" value ="Reply" style="background-color:#0D52C7;">
</div>
</div>
</form>

</br>
<?php

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

mysqli_query($con,"insert into comment (comment,date_posted,user_id,comment_id) values ('$comment_content','".strtotime(date("Y-m-d h:i:sa"))."','$user_id','$post_id')") or die (mysqli_error());
header('Location: comment.php');
exit();
ob_end_flush();}
?>

<?php
$comment_query = mysqli_query($con,"SELECT DISTINCT DISTINCT * ,UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment inner JOIN registration on registration.user_id = comment.user_id where comment_id = '$id' order by date_posted DESC") or die (mysqli_error());
while ($comment_row=mysqli_fetch_array($comment_query)){
$comment_id = $comment_row['id'];
$comment_by = $comment_row['username'];
?>
<div class="container col-md-6 bg-body-tertiary border rounded-3">
Comment by: <a href="#" style= "margin-left:10px; text-decoration:none;"> <?php echo $comment_by; ?></a>
<div class="" style="font-size:12px;">
<?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';
?>
<img src ="../images/hour.png" alt = "My hour" style ="width:12px;">
</div>


<div class="mb-3">
<?php echo $comment_row['comment']; ?>
</div>
</div>

<br>

<?php
}}?>


<hr>

<?php
include "../partials/footer.php";
?>


</body>
</html>
 
Based on your code, it seems that you are retrieving the comment content based on the comment ID. However, you are not passing the comment ID correctly in the URL when you click on the title.

In your title.php file, you have the following code for the link to the comment page:

PHP:
<a href="comment.php?id=<?php echo $id_comment;?>"><?php echo $post_row['title']; }?></a>

Here, you are using $id_comment as the comment ID. However, in your while loop, you are not setting the value of $id_comment. You are only setting the value of $id. To fix this, you need to change this line:

PHP:
$id_comment = $post_row ['comment_id'];

to:

PHP:
$id_comment = $post_row['id'];

This will set the correct comment ID for each title.

In your comment.php file, you have the following code to fetch the specific content based on the comment ID:

PHP:
$content_query = mysqli_query($con, "SELECT * FROM post WHERE comment_id = '$id_comment'") or die(mysqli_error());

However, in your while loop, you are using the $post_row variable from the previous query to display the comment content:

PHP:
while($post_row = mysqli_fetch_array($post_query)){
    // ...
    <h6><?php echo $post_row['comment']; ?></h6>
    // ...
}

To fix this, you need to change $post_row to $content_row in the while loop:

PHP:
while($content_row = mysqli_fetch_array($content_query)){
    // ...
    <h6><?php echo $content_row['comment']; ?></h6>
    // ...
}

This will display the correct comment content on the comment page.

Additionally, please make sure that you have established a database connection ($con) before executing any queries, and also sanitize user inputs to prevent SQL injection attacks.
 
Based on your code, it seems that you are retrieving the comment content based on the comment ID. However, you are not passing the comment ID correctly in the URL when you click on the title.

In your title.php file, you have the following code for the link to the comment page:

PHP:
<a href="comment.php?id=<?php echo $id_comment;?>"><?php echo $post_row['title']; }?></a>

Here, you are using $id_comment as the comment ID. However, in your while loop, you are not setting the value of $id_comment. You are only setting the value of $id. To fix this, you need to change this line:

PHP:
$id_comment = $post_row ['comment_id'];

to:

PHP:
$id_comment = $post_row['id'];

This will set the correct comment ID for each title.

In your comment.php file, you have the following code to fetch the specific content based on the comment ID:

PHP:
$content_query = mysqli_query($con, "SELECT * FROM post WHERE comment_id = '$id_comment'") or die(mysqli_error());

However, in your while loop, you are using the $post_row variable from the previous query to display the comment content:

PHP:
while($post_row = mysqli_fetch_array($post_query)){
    // ...
    <h6><?php echo $post_row['comment']; ?></h6>
    // ...
}

To fix this, you need to change $post_row to $content_row in the while loop:

PHP:
while($content_row = mysqli_fetch_array($content_query)){
    // ...
    <h6><?php echo $content_row['comment']; ?></h6>
    // ...
}

This will display the correct comment content on the comment page.

Additionally, please make sure that you have established a database connection ($con) before executing any queries, and also sanitize user inputs to prevent SQL injection attacks.
wala pa rin po
 
wala pa rin po
Apologies for any confusion. Upon reviewing your code again, I noticed a few issues that may be causing the problem.

1. In your title.php file, you are not closing the while loop properly. The closing brace (}) for the while loop is missing. To fix this, add a closing brace after the line <a href="comment.php?id=<?php echo $id_comment;?>"><?php echo $post_row['title']; ?></a> like this:

PHP:
<a href="comment.php?id=<?php echo $id_comment;?>"><?php echo $post_row['title']; ?></a>
<?php } ?>

2. In your comment.php file, you are not correctly passing the comment ID to the query. By using $_GET['id'], you can access the comment ID passed in the URL. Modify the line $id_comment = $_GET['id']; to this:

PHP:
$id_comment = $_GET['id_comment'];

3. In the same comment.php file, the query that fetches the specific content based on the comment ID is incorrect. Update the query line to this:

PHP:
$content_query = mysqli_query($con, "SELECT * FROM post WHERE comment_id = '$id_comment'") or die(mysqli_error($con));

Make sure to pass the database connection variable $con and handle any potential database errors.

4. Additionally, there is a syntax error in the line <input class="w-25" type="submit" name="comment" value ="Reply" style="background-color:#0D52C7;">. You have an extra closing parenthesis ) at the end. Remove the extra parenthesis to fix the syntax error.

Please make these changes and test your code again. If the issue persists, please provide more details or error messages that may help in diagnosing the problem.
 

Similar threads

Back
Top