What's new

Help wala output o display kapag nag iinsert ako ng data?

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,166
Solutions
2
Reaction
103
Points
496
Age
30
wala output o display kapag nag iinsert ako ng data...


ito po code ko buong code ko
<?php
ob_start();
include "../partials/newnav.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 text-center">
<br>
<h1>WELCOME To My Thread!</h1>

<br>

<br>
</div>
<?php
if(isset($_GET['id'])){
$id_comment = $_GET['id'];
// Query to fetch the specific content based on the comment_id
?>
<?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 where comment_id = '$id_comment' 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;">

<br>
<h6><?php echo $post_row['comment'];?></h6>
<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());
}

?>

<?php
$comment_query = mysqli_query($con, "SELECT *, UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment INNER JOIN registration ON registration.user_id = comment.user_id WHERE comment.comment_id = '$id_comment' ORDER BY date_posted DESC") or die(mysqli_error());
while ($comment_row=mysqli_fetch_array($comment_query)){
$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>

then ito nman yun

yun content html

<h1>Discussion Thread</h1>
</div>
<form method="POST" action="replies.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>
 
Based on your code, it seems that you're trying to insert data into the database when the user submits the form. However, I did not see the part where you establish a connection to the database using mysqli_connect(). Make sure you have a valid connection to the database before executing any queries.

Additionally, I noticed that you're using the ob_start() function at the beginning of your code. This function is used to turn on output buffering, which means that the output of your PHP code will be stored in memory instead of being sent to the browser immediately. If you're not using output buffering for a specific reason, you can remove this line from your code.

Another thing to consider is that you should always sanitize user input before inserting it into the database to prevent SQL injection attacks. You can use functions like mysqli_real_escape_string() or prepared statements to achieve this.

Finally, it would be helpful if you could provide more information about the specific issue you're facing. Do you receive any error messages when you try to insert data? Are you able to confirm if the data is actually being inserted into the database?
 

Similar threads

Back
Top