What's new

Updated ko po phc robot

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,168
Solutions
2
Reaction
103
Points
497
Age
30
kapag pinipindot ko yun content sa title.php nakaasssign na sya sa kanya kanya id hindi na nahahalo..
ang problima ko na lang po is kapag mag rereply po ako sa isang content at nag click ko ng submit..
wala na po syang display o output kahit ireload ko pa o irefresh wala tlga sya display pero kapag bumalik ako sa title.php at pinindot ko yun content na kung saan ako nag reply lalabas na yun reply message ko...

updated code..
<!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'];
?>
<?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']; ?>


<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:home.php');
}
?>
</body>
<?php include('footer.php');?>
</html>
 
Based on the code you provided, it seems that the issue lies in the submit functionality of the comment form. After submitting the comment, the page is not displaying the updated content.

To address this issue, you can try adding a redirect to the same page after the form submission. This will reload the page and display the updated content.

Here's an updated version of the code with the redirect added:

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);
    exit();
}
?>

In this updated code, header('location: ' . $_SERVER['PHP_SELF'] . '?id=' . $post_id); is added after the comment is inserted into the database. This redirects the page to itself ($_SERVER['PHP_SELF']) with the post ID (?id=$post_id) in the URL. This will reload the page with the updated content.

Make sure to replace the existing code with this updated code and test it again to see if the issue is resolved.
 
Based on the code you provided, it seems that the issue lies in the submit functionality of the comment form. After submitting the comment, the page is not displaying the updated content.

To address this issue, you can try adding a redirect to the same page after the form submission. This will reload the page and display the updated content.

Here's an updated version of the code with the redirect added:

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);
    exit();
}
?>

In this updated code, header('location: ' . $_SERVER['PHP_SELF'] . '?id=' . $post_id); is added after the comment is inserted into the database. This redirects the page to itself ($_SERVER['PHP_SELF']) with the post ID (?id=$post_id) in the URL. This will reload the page with the updated content.

Make sure to replace the existing code with this updated code and test it again to see if the issue is resolved.
yun content ko naman nawala kapag mag lalagay ako ng bago content sya naman di nag didisplay o nag ooutput
 
yun content ko naman nawala kapag mag lalagay ako ng bago content sya naman di nag didisplay o nag ooutput
Apologies for the confusion. It seems that the code you provided is missing the part where the content is displayed after submitting a new comment. To resolve this issue, you need to modify the code to include the updated content in the display.

Here's an updated version of the code with the necessary modifications:

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());
    // Retrieve the updated content after inserting the comment
    $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 = '$post_id' LIMIT 1") or die(mysqli_error());
    while ($post_row = mysqli_fetch_array($query)) {
        $id = $post_row['post_id'];
        $posted_by = $post_row['firstname'] . " " . $post_row['lastname'];
        // Display the updated content including the new comment
        ?>
        <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
    }
    exit();
}
?>

In this updated code, after inserting the comment, the code fetches the updated content from the database and displays it, including the newly added comment.

Make sure to replace the existing code with this updated code and test it to see if the issue is resolved.
 
Apologies for the confusion. It seems that the code you provided is missing the part where the content is displayed after submitting a new comment. To resolve this issue, you need to modify the code to include the updated content in the display.

Here's an updated version of the code with the necessary modifications:

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());
    // Retrieve the updated content after inserting the comment
    $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 = '$post_id' LIMIT 1") or die(mysqli_error());
    while ($post_row = mysqli_fetch_array($query)) {
        $id = $post_row['post_id'];
        $posted_by = $post_row['firstname'] . " " . $post_row['lastname'];
        // Display the updated content including the new comment
        ?>
        <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
    }
    exit();
}
?>

In this updated code, after inserting the comment, the code fetches the updated content from the database and displays it, including the newly added comment.

Make sure to replace the existing code with this updated code and test it to see if the issue is resolved.
kaapg nag ccreate ako ng bagong content wala sya output o display

ito po code ko sa 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 code ko sa output o home.php

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

Similar threads

Back
Top