doujie4344 2013-06-14 17:59
浏览 580

单击按钮时,重新加载页面/表单以刷新数据

How to reload the page or form in PHP.

The scenario: I have two forms with the same design/gui. I named it main.php and process.php. Both page also have dropdownlist, same items. The items in the dropdownlist are "Net 1" and "Net 2" and under of "Net 1" is "Bldg 1" and for "Net 2" is "Bldg 2". So in the main.php when I click the submit it will proceed to the process.php. Then process.php will display the under item of the item I choose in the dropdownlist in main.php.

My problem is: When the user want to see the under item of "Net 2". I want is, in the page of button_process.php will just reload or refresh the data so that the user will see the items for "Net 2", what should I do?

Code for main.php:

    <form action="process.php" method="post">
 Advertisement Name: <input type="text" name="adName" size="50"><br/><br/>
 Duration: <select id="duration"name="duration">
     <option value="5 s" >5 s</option>
         <option value="10 s" >10 s</option>
    <option value="15 s" >15 s</option>
    <option value="20 s" >20 s</option>
    <option value="30 s" >30 s</option>
    <option value="60 s" >60 s</option>
    </select><br/><br/>
    <b>Period</b>  <br/>
     From: <input type="text" id="datepickerfrom"name="from"> To: <input type="text" id="datepickerto"name="to">

    <span id="span_select">
        <select name="id">
            <option value="" >- select -</option>

            <?php
                include 'connect.php';

                $q = mysql_query("select fldNetname from tblnetwork");

                while ($row1 = mysql_fetch_array($q))
                {
                  echo "<option value='".$row1[fldNetname]."'>".$row1[fldNetname]."</option>";

                }
            ?>
        </select>
    </span>
    <input type="submit" name="pass" value="View Building/s">   
    </form>
Here's my Code for 

process.php: EDIT:

<form action="button_process.php" method="post">
echo "<div><input type='checkbox' class='checkall'> Check all</div>";
    $all = mysql_query("SELECT fldBldgName FROM tblbuildings");
    while ($row = mysql_fetch_array($all))
       {

       echo "<div><input type='checkbox' name='play[]' class='chk_boxes1' value='" . $row['fldBldgName']."'>";
       echo $row['fldBldgName'];"</div>";

       }


<input type="submit" name="pass" value="View Building/s">   
</form>

Code for button_process.php

<?php
include("connect.php");

switch ($_POST['pass']) {
      case 'View':
           //here I want to reload the page.
            break;


      case 'Save':
            echo "Add";
            break;
}

?>
  • 写回答

2条回答 默认 最新

  • doujiong2533 2013-06-14 18:10
    关注

    If reloading the page requires a user action, you will not be able to use PHP to reload the page, in this case, you would have to use Javascript.

    If you want to reload a page using PHP, which will happen as the page load and before any html code is outputted, you can use this :

    header('Location: '.$_SERVER['REQUEST_URI']);
    

    If you want to refresh the page after the user has executed an action, you will need a javascript event method on an element (for exemple, onclick() on a button), and within the method you can use the following code :

    window.location.reload();
    

    If this isn't sufficient to answer your question, please provide more details as to what you want to do. There is a better way to do it than what you are doing, with more details we might be able to help you more.

    评论

报告相同问题?

悬赏问题

  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题