What's new

Pano ko kaya gagawin to..

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,166
Solutions
2
Reaction
103
Points
496
Age
30
plano ko kasi na mula sa thread.php papunta sa thead.php to title.php to home.php
mangyayari po ganito mag lalagay ako ng content sa thread.php then dadalhin nya patungo sa thead.php then ididisplay nya sa home.php
kaso nga sa home.php meron lumalabas sa url nya na ganito You do not have permission to view the full content of this post. Log in or register now. gusto kung anu number nya is dun nya dadalhin home.php...
ito code ko sa home.php
<?php
error_reporting(E_ALL);
?>
<!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());

}
?>

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

ito naman code ko sa thead.php

<?php include('dbconn.php'); ?>
<?php include('session.php'); ?>

<?php
$query = mysqli_query($conn,"SELECT *,UNIX_TIMESTAMP() - date_created AS TimeSpent from post LEFT JOIN user on user.user_id = post.user_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>
<?php
}?>
<?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');
}
?>
 
Based on the code you provided, it seems like you want to pass the post ID from the thread.php page to the home.php page. Currently, the post ID is being passed through the URL as a query parameter. If you want to hide the post ID from the URL, you can use PHP sessions to store the post ID and access it on the home.php page.

Here's an updated version of your code:

In thread.php:
PHP:
<?php include('dbconn.php'); ?>
<?php include('session.php'); ?>

<?php 
$query = mysqli_query($conn,"SELECT *,UNIX_TIMESTAMP() - date_created AS TimeSpent from post LEFT JOIN user on user.user_id = post.user_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'];
    $_SESSION['post_id'] = $id; // Store the post ID in a session variable
    ?>
    <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
    // Rest of your code
}
?>

In home.php:
PHP:
<?php
error_reporting(E_ALL);
include('dbconn.php');
include('session.php');

if (isset($_SESSION['post_id'])) {
    $id = $_SESSION['post_id'];
    unset($_SESSION['post_id']); // Remove the post ID from the session after using it
    // Rest of your code
} else {
    // Handle case when there is no post ID in the session
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>POST AND COMMENT SYSTEM</title>
    <!-- Rest of your code -->
</head>
<body>
    <!-- Rest of your code -->
</body>
<?php include('footer.php');?>
</html>

In the updated code, the post ID is stored in a session variable $_SESSION['post_id'] on the thread.php page. Then, on the home.php page, you check if the post ID is present in the session. If it is, you retrieve it, unset the session variable, and use the post ID in your code. This way, the post ID is not exposed in the URL.
 

Similar threads

Back
Top