首先让我们解释一下我想做什么,然后再问我的问题! 好吧,我想对查询使用搜索过滤器(用户应该选择搜索数据库的字段,例如按名称、代码或 fname)查询运行后,我想在某些文本字段中显示数据,所以用户可以更改它们。
为此,我将第一部分(搜索过滤器 - radio 组 - 和过滤器值 - 文本字段 -)放在我的第一页(getStudentFilter.php
)中。提交后,查询运行,我将值放入 SESSION
并使用我的正确数据打开第二页 (change_user.php
)!
如果用户更改学生的数据,数据库中的更新是可以的,但在页面 change_user.php
中它再次显示初始数据。
我试图更改 SESSION
值,以便在运行更新查询之前保留我的新值,但这似乎是错误的。
有人可以给我一个解决方案,以便我解决问题吗?这可以按原样完成,还是我必须更改它并将两个查询(选择和更新)放在一种形式中? Aaahh,我试图将两者都放在一种形式中,但我不知道如何以一种形式控制两个“提交”...
提前致谢..
修改后的代码是
<form name="change_student" method="post" enctype="multipart/form-data" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" >
<?php
if ( isset($_POST['upd_student']) && $_POST['upd_student'] = 'Change' ){
echo "UPDATE";
//RUN UPDATE QUERY
}
elseif( isset($_POST['get_filter']) && $_POST['get_filter'] == 'Show' ){
echo "SELECT";
$query = "select * from student where ".$_POST['filter']."='".$_POST['filter_val']."'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$id = $row['idstudent'];
$fn = $row['fname'];
$ln = $row['lname'];
$ph = $row['phone'];
$sc = $row['school_dept'];
echo "<META HTTP-EQUIV='Refresh' CONTENT='0' >";
}
?>
<table width="310">
<tr><td><label><b>FILTER</b></label></td> </tr>
<tr><td><label><input type="radio" name="filter" value="idstudent" id="filter_5">ID </label></td></tr>
<tr><td><label><input type="radio" name="filter" value="fname" id="filter_3">FIRST NAME</label></td></tr>
<tr><td><label><input type="radio" name="filter" value="lname" id="filter_4">LAST NAME</label></td></tr>
<tr><td><input type="text" name="filter_val"> </td></tr>
<tr><td><input type="submit" name="get_filter" id="get_filter" value="Show"></td></tr>
</table>
<table>
<th colspan="2">STUDENT'S DATA</th>
<tr><td>ID</td><td><input type="text" name="st_id" value="<?php echo $id?>"></td></tr>
<tr><td>FIRST NAME</td><td><input type="text" name="fname" value="<?php echo $fn?>"></td></tr>
<tr><td>LAST NAME</td><td><input type="text" name="lname" value="<?php echo $ln?>"></td></tr>
<tr><td>PHONE</td><td><input type="text" name="phone" value="<?php echo $ph?>"></td></tr>
<tr><td>DEPT</td><td><input type="text" name="dept" value="<?php echo $sc?>"></td></tr>
</table>
<input type="submit" name="upd_student" value="Change">
</form>
最佳答案
不要将搜索参数放入 session 中。
不要使用 2 页。
将所有内容都放在一个页面上,并使用 GET 方法传递搜索参数,就像每个搜索工具所做的那样。
关于php - 从当前 php 刷新另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5067640/