在php中将用户重定向到同一页面问题
我正在用php创建一个博客,mysql(PDO)。在博客中,我创建了这样一种逻辑,当新用户出现时,它将首先登录,然后他/她将能够看到帖子和评论。现在我在评论部分遇到了一个问题。。。 我创建了一个评论表,每个用户的评论都将保存在该表中,当管理员批准该评论时,该评论将显示在Concernd页面上 主要问题: 当用户评论页面重新加载时,我收到一些通知,我知道通知的原因,原因是当用户单击帖子查看其详细内容时,帖子将代表Id打开,但当用户评论帖子并重新加载页面时,页面无法找到相关的帖子Id,它会显示通知 这是我的评论表图片 这是我的贴页代码……在php中将用户重定向到同一页面问题,php,mysql,pdo,blogs,Php,Mysql,Pdo,Blogs,我正在用php创建一个博客,mysql(PDO)。在博客中,我创建了这样一种逻辑,当新用户出现时,它将首先登录,然后他/她将能够看到帖子和评论。现在我在评论部分遇到了一个问题。。。 我创建了一个评论表,每个用户的评论都将保存在该表中,当管理员批准该评论时,该评论将显示在Concernd页面上 主要问题: 当用户评论页面重新加载时,我收到一些通知,我知道通知的原因,原因是当用户单击帖子查看其详细内容时,帖子将代表Id打开,但当用户评论帖子并重新加载页面时,页面无法找到相关的帖子Id,它会显示通知
<?php
session_start();
include 'conn.php';
if(!isset($_SESSION['user']))
{
header('location:signin.php');
}
$smt=$conn->prepare("SELECT * FROM post,images WHERE post.Id=images.Id");
$smt->execute();
?>
<?php include 'header.php';?>
<?php
if(isset($_SESSION['user']))
{
include 'nav.php';
}
else
{
include 'nav-simple.php';
}
?>
<div class="container-fluid">
<?php include 'right_sidebar.php';?>
<div class="main-container-top" id="masonry-grid">
<?php while($rows=$smt->fetch(PDO::FETCH_OBJ)):
?>
<div class="col-md-3 grid-item post-col">
<img src="image/<?php echo $rows->Image_Name;?>" data-echo="image/<?php echo $rows->Image_Name;?>" class="post-image"/>
<h5>Post On <?php echo $rows->Post_Date;?></h5>
<a href="post-description.php?id=<?php echo $rows->Id ?>" <h4><?php echo $rows->Post_Title;?></h4></a>
<p>
<?php echo $rows->Post;?>
</p>
</div>
<?php endwhile;
?>
</div>
</div>
<?php include 'footer-content.php';?>
<?php include 'footer.php';?>
<?php
session_start();
include 'conn.php';
$pic_id='';
if(isset($_GET['id']))
{
$pic_id=$_GET['id'];
}
$smt=$conn->prepare("SELECT * FROM post,images WHERE post.Id = images.Id AND post.Id='".$pic_id."'");
$smt->execute();
$rows=$smt->fetch(PDO::FETCH_OBJ);
$title=$rows->Post_Title;
$img=$rows->Image_Name;
$post=$rows->Post;;
?>
<?php include 'header.php';?>
<?php include 'nav.php';?>
<div class="container-fluid">
<?php include 'right_sidebar.php';?>
<div class="col-md-1"></div>
<div class="col-md-9 main-container-top container">
<div class="media col-md-12 description-post">
<img src="image/<?php echo $img;?>" alt="<?php echo $img;?>" class="img-rounded img-responsive media-left img-description"/>
<div class="media-body">
<h4 class="h4 description-heading"><?php echo $title;?></h4>
<p class="post-text text-justify text-info">
<?php echo $post;?>
</div>
</div>
<br/>
<div class="media col-md-12 comment-section">
<?php
if(isset($_SESSION['comment-error']))
{
?>
<span class="alert alert-warning col-md-6 container col-md-offset-3"><?php echo $_SESSION['comment-error']; ?></span>
<?php
}
unset($_SESSION['comment-error']);
if(isset($_SESSION['comment-success']))
{
?>
<span class="alert alert-success col-md-6 container col-md-offset-3"><?php echo $_SESSION['comment-success']; ?></span>
<?php
}
unset($_SESSION['comment-success']);
?>
<br/>
<span class="col-md-1 comment-pic"><img src="profile%20picture/cv.jpg" alt="post image" class="img-thumbnail img-responsive comment-img"/></span>
<div class="media-body comment-head col-md-10">
<h6 class="h6">comment by <a href="#">e</a> on Thursday 9.00 PM</h6>
<p class="comment"></p>
</div>
</div>
<br/>
<div class="col-md-12 container">
<h4 class="description-heading h4 text-muted">Share your thought</h4>
<br/>
<form action="comment.php" method="post" class="col-md-12" id="commentForm">
<textarea name="comment" id="" cols="100" rows="5" placeholder="Your comment"></textarea>
<br/>
<input type="submit" value="Post" name="cmsg" id="<?php echo $pic_id;?>" class="btn btn-info"/>
<br/>
</form>
</div>
<br/>
</div>
</div>
<?php include 'footer-content.php';?>
<?php include 'footer.php';?>
图像名称;?>“data echo=“image/”class=“post image”/
张贴
下面是我的帖子描述页面代码,我在其中有一个评论部分,这是我面临问题的页面…
<?php
session_start();
include 'conn.php';
if(!isset($_SESSION['user']))
{
header('location:signin.php');
}
$smt=$conn->prepare("SELECT * FROM post,images WHERE post.Id=images.Id");
$smt->execute();
?>
<?php include 'header.php';?>
<?php
if(isset($_SESSION['user']))
{
include 'nav.php';
}
else
{
include 'nav-simple.php';
}
?>
<div class="container-fluid">
<?php include 'right_sidebar.php';?>
<div class="main-container-top" id="masonry-grid">
<?php while($rows=$smt->fetch(PDO::FETCH_OBJ)):
?>
<div class="col-md-3 grid-item post-col">
<img src="image/<?php echo $rows->Image_Name;?>" data-echo="image/<?php echo $rows->Image_Name;?>" class="post-image"/>
<h5>Post On <?php echo $rows->Post_Date;?></h5>
<a href="post-description.php?id=<?php echo $rows->Id ?>" <h4><?php echo $rows->Post_Title;?></h4></a>
<p>
<?php echo $rows->Post;?>
</p>
</div>
<?php endwhile;
?>
</div>
</div>
<?php include 'footer-content.php';?>
<?php include 'footer.php';?>
<?php
session_start();
include 'conn.php';
$pic_id='';
if(isset($_GET['id']))
{
$pic_id=$_GET['id'];
}
$smt=$conn->prepare("SELECT * FROM post,images WHERE post.Id = images.Id AND post.Id='".$pic_id."'");
$smt->execute();
$rows=$smt->fetch(PDO::FETCH_OBJ);
$title=$rows->Post_Title;
$img=$rows->Image_Name;
$post=$rows->Post;;
?>
<?php include 'header.php';?>
<?php include 'nav.php';?>
<div class="container-fluid">
<?php include 'right_sidebar.php';?>
<div class="col-md-1"></div>
<div class="col-md-9 main-container-top container">
<div class="media col-md-12 description-post">
<img src="image/<?php echo $img;?>" alt="<?php echo $img;?>" class="img-rounded img-responsive media-left img-description"/>
<div class="media-body">
<h4 class="h4 description-heading"><?php echo $title;?></h4>
<p class="post-text text-justify text-info">
<?php echo $post;?>
</div>
</div>
<br/>
<div class="media col-md-12 comment-section">
<?php
if(isset($_SESSION['comment-error']))
{
?>
<span class="alert alert-warning col-md-6 container col-md-offset-3"><?php echo $_SESSION['comment-error']; ?></span>
<?php
}
unset($_SESSION['comment-error']);
if(isset($_SESSION['comment-success']))
{
?>
<span class="alert alert-success col-md-6 container col-md-offset-3"><?php echo $_SESSION['comment-success']; ?></span>
<?php
}
unset($_SESSION['comment-success']);
?>
<br/>
<span class="col-md-1 comment-pic"><img src="profile%20picture/cv.jpg" alt="post image" class="img-thumbnail img-responsive comment-img"/></span>
<div class="media-body comment-head col-md-10">
<h6 class="h6">comment by <a href="#">e</a> on Thursday 9.00 PM</h6>
<p class="comment"></p>
</div>
</div>
<br/>
<div class="col-md-12 container">
<h4 class="description-heading h4 text-muted">Share your thought</h4>
<br/>
<form action="comment.php" method="post" class="col-md-12" id="commentForm">
<textarea name="comment" id="" cols="100" rows="5" placeholder="Your comment"></textarea>
<br/>
<input type="submit" value="Post" name="cmsg" id="<?php echo $pic_id;?>" class="btn btn-info"/>
<br/>
</form>
</div>
<br/>
</div>
</div>
<?php include 'footer-content.php';?>
<?php include 'footer.php';?>
首先尝试此注释部分获取图像id
<form action="comment.php" method="post" class="col-md-12" id="commentForm">
<textarea name="comment" id="" cols="100" rows="5" placeholder="Your comment"></textarea>
<input type="hidden" name="image-id" value="<?php echo '?id='.$pic_id;?>"/>
<br/>
<input type="submit" value="Post" name="cmsg" id="" class="btn btn-info"/>
<br/>
</form>
注意根据需要管理您的代码,我只为您提供重定向解决方案。上面的代码对我来说很好…请注意您的代码容易受到SQL注入的攻击。另外,请注意不要受到XSS的攻击。ad 2您需要添加where Status=“accepted“要查询ad 3,请尝试打印变量$rows,检查执行函数的状态。”