开发者

refresh another page from current php

First let's explain what I want to do and then ask my question! Well, I want to use a search filter for a query (the user should choose by which field will search the database, eg by name, code or fname) After the query runs, I want to show the data in some textfields, so the user can change th开发者_如何学JAVAem.

To do this, I put the first part (search filter-radio group- and filter value-text field-) in my first page(getStudentFilter.php). On submit, the query runs, I put values in SESSION and opens the second page(change_user.php) with my correct data! If user change student's data, the update in db is ok, but in page change_user.php it shows the initial data again.

I tried to change SESSION values so I can keep my new values before run the update query, but it seems wrong.

Can someone give me a solution so I can fix the problem? Can this be done as it is or I have to change it and put both queries (select and update) in one form? Aaahh, I tried to put both in one form but I don't know how to control two "submit" in one form...

Thanks in advance..

my code after changes is

<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>


Do not put search params into session.
Do not use 2 pages.

Make it all on one page and pass search parameters using GET method, like every search facility does.


To control 2 submits in one form you would have to test the values in you're php script .

Let's take the following html form:

<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>

Now in you're php script you would do this :

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";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜