刷新当前php的另一个页面

时间:2011-02-21 15:15:15

标签: php mysql

首先让我们解释一下我想做什么然后问我的问题! 好吧,我想使用搜索过滤器进行查询(用户应该选择通过哪个字段搜索数据库,例如通过名称,代码或fname)查询运行后,我想在某些文本字段中显示数据,所以用户可以更改它们。

为此,我将第一部分(搜索过滤器 - 无线电组 - 和过滤器值 - 文本字段 - )放在我的第一页(getStudentFilter.php)中。在提交时,查询运行,我将值放在SESSION中,并使用正确的数据打开第二页(change_user.php)! 如果用户更改学生的数据,则db中的更新正常,但在页面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>

2 个答案:

答案 0 :(得分:3)

不要将搜索参数放入会话中 不要使用2页。

在一个页面上完成所有操作并使用GET方法传递搜索参数,就像每个搜索工具一样。

答案 1 :(得分:1)

要在一个表单中控制2个提交,您必须在php脚本中测试值。

让我们采用以下html格式:

<form  action="index.php" name="contestForm" id="contestForm" method="POST">
    <input type="submit" value="Select" name="select" />
    <input type="submit" value="Update" name="update" />
</form>

现在你的PHP脚本你会这样做:

if ( isset($_POST['update']) && $_POST['update'] = 'Update' )
{
    //do the update part
    echo "UPDATE";
} elseif ( isset($_POST['select']) && $_POST['select'] == 'Select' )
{
    //do the select part
    echo "SELECT";
}
相关问题