我正在制作社交项目表单并且我正在尝试添加回复..回复按钮是一个链接,用户将回复信息发送到answer.php页面,帖子ID保存在href ...上,我的表单操作是相同的页面,但当我点击按钮提交表单时,它没有获取id和刷新页面的帖子和显示错误未定义id需要帮助..
这是我的回复.php
<?php
require('session.php');
$id=$_GET['id'];
//echo $id;
$submit=@$_POST['submit'];
$reply=@$_POST['reply'];
if(isset($submit)){
$id=@$_GET['id'];
$sql=mysqli_query($con,"INSERT INTO REPLY (reply,Username,post_id) VALUES '$reply','$user_check','$id'");
$sql2=mysqli_query($con,"SELECT * FROM REPLY WHERE post_id= '$id'");
while($row=mysqli_fetch_array($sql2)){
echo $row['Username']."<br/>".$row['reply']."<br/>";
}
}
else "error in submission";
?>
<!DOCTYPE html>
<html>
<title>Studhelp</title>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="w3.css">
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<script src="bootstrap/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
<?php
$sql=mysqli_query($con,"select * from posts where post_id='$id'");
while($row=mysqli_fetch_array($sql)){?>
<!-- Middle Column -->
<div class="w3-col m7">
<div class="w3-row-padding">
<div class="w3-col m12">
<div class="w3-card-2 w3-round w3-white">
<div class="w3-container w3-padding">
<h3 class="w3-opacity"><?php echo $row['Username'] ;?></h3>
<?php
echo $row['Posts']."<br/>".$row['date']."<br/>";
}
?>
</p>
</div>
</div>
</div>
</div>
<form action="reply.php" method="post">
<input type="text" name="reply" >
<input type="submit" name="submit" value="reply">
</form>
这是锚标记发送id到reply.php
<a href="reply.php?id=<?php echo $row['post_id']; ?>" class="reply-comment"> Reply </a>
答案 0 :(得分:0)
如果我理解正确,你需要能够阅读你的&#34; id&#34;发布表单后的变量。要实现这一点,请使用$ _REQUEST而不是$ _GET,如下所示:
$id = $_REQUEST['id'];
并且还将变量与您的表单一起传递为隐藏字段:
<form action="reply.php" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<input type="text" name="reply" />
<input type="submit" name="submit" value="reply" />
</form>
答案 1 :(得分:0)
您没有检查fom是否已提交
将session.php之后的其他PHP代码包含在条件检查器中,例如:
if($ _POST):
您可以使用表单标签创建表单并将id字段隐藏起来。
GET请求不应用于修改数据