gpt4 book ai didi

php - 无法从组 id 2 中的表单插入数据库,但它插入到组 id 1 中

转载 作者:行者123 更新时间:2023-11-29 19:46:35 25 4
gpt4 key购买 nike

                 <form method="post" action="" class="form-horizontal no-margin well">
<div class="control-group">
<input type="text" name="post" id="post" style="
width: 98%;
height: 50px;"/> </div>
<div style="padding-left:95%!important" class="form-actions no-margin">
<button onClick="window.location.reload(true);" style="height:30px" name="submit" type="submit" class="btn btn-info">
<p>Post</p></button>
</div>
</form>
<?php
$link=mysql_connect("localhost","root","")or die("Can't Connect...");
mysql_select_db("project") or die("Can't Connect to Database...");
$q="SELECT * FROM post p , member m , groupp g WHERE p.group_id='".$dbgroupid."' and p.m_id=m.m_id ORDER BY p_id DESC";
$queryRessource = mysql_query($q,$link) or die(mysql_error());
$numrows=mysql_num_rows($queryRessource);
if($numrows > 0)
{
while($row = mysql_fetch_array($queryRessource )) {
echo"<br><table border=\"1\" width=\"100%\"><tr><td valign=\"top\" style=background:#f4f4f4;;height:100px><b>".$row['username']."</b><br />".$row['post']."</td></tr><tr><td valign=\"top\" style=background:#f4f4f4;;height:100px>
<form method=\"post\" action=\"\" class=\"form-horizontal no-margin well\">
<input type=\"text\" name=\"comment".$row['p_id']."\" id=\"comment\" />
<button onClick=\"window.location.reload(true);\" style=\"height:30px\" name=\"submit".$row['p_id']."\" type=\"submit\" class=\"btn btn-info\"> Comment</button></form></td></tr></table>";


$qq="SELECT * FROM comment c , member m WHERE c.p_id='".$row['p_id']."'and c.m_id=m.m_id";
$queryRessource1 = mysql_query($qq,$link) or die(mysql_error());
$numrows1=mysql_num_rows($queryRessource1);
if($numrows1 > 0)
{
echo "<table border=\"1\" width=\"100%\">";
while($row1 = mysql_fetch_array($queryRessource1 ))
{echo"<tr><td valign=\"top\" style=background:#f4f4f4;;height:100px>"
."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>".$row1['username']."</b><br />"."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$row1['comment']."</td></tr>";
}
echo "</table>";
}
if(isset($_POST['submit'.$row['p_id']]))
{
if(empty($_POST['comment'.$row['p_id']]))
{
echo '<script language="javascript">';
echo 'alert("You Cant Add Empty Comment")';
echo '</script>';
}
else {
$p_id=$row['p_id'];
$dbmemberid=$_SESSION['Member_ID'];
$comment=$_POST['comment'.$row['p_id']];
$link=mysql_connect("localhost","root","")or die("Can't Connect...");
mysql_select_db("project") or die("Can't Connect to Database...");
$Query="INSERT INTO `comment`(`comment_id`,`comment`,`p_id`,`group_id`,`m_id`) VALUES ('','$comment','$p_id','$dbgroupid','$dbmemberid')";
mysql_query($Query,$link)or die (mysql_error());
echo "<meta http-equiv='refresh' content='0'>";

}}

}

if(isset($_POST['submit']))
{
if(empty($_POST['post']))
{
echo '<script language="javascript">';
echo 'alert("You Cant Add Empty Post")';
echo '</script>';
}
else {
$post=$_POST['post'];
$link=mysql_connect("localhost","root","")or die("Can't Connect...");
mysql_select_db("project") or die("Can't Connect to Database...");
$query="INSERT INTO `post` VALUES ('','$post','$dbmemberid','$dbgroupid')";
mysql_query($query,$link)or die (mysql_error());
echo "<meta http-equiv='refresh' content='0'>";

}}
?>

我的问题是,我通过使用 $_get 获得了组 session ID,但是当我尝试插入组 2 (group_id=2) 时,它没有插入到数据库中,而是在组 id 1 (group_id=1) 中时插入到数据库中)

我的 session 设置为

if(isset($_SESSION['UserName']) && isset($_SESSION['Member_ID']))
{
$dbusername=$_SESSION['UserName'];
$dbmemberid=$_SESSION['Member_ID'];
$dbgroupid=$_GET['group_id'];

}

那么我需要做什么才能让我的表单发布在第二组中当我在群组 id=1 中插入帖子或评论时第 num 行回显每个帖子两次...

最佳答案

尝试为您的表单指定一个操作。即。

<?php $id = $_GET['id']; ?> 

<form method = "POST" action = "current_page.php?id=<?php echo $id; ?>">

关于php - 无法从组 id 2 中的表单插入数据库,但它插入到组 id 1 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40937300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com