好吧,我有這個下拉填充一個Mysql數據庫。在更改下拉菜單時,整個頁面會填充來自數據庫的信息。那麼當我提交這個表單時(我們在這個頁面上有兩個表單),我希望它返回到我剛剛在下拉菜單中選擇的同一個客戶機。現在,我正在使用一個會話將其恢復並選擇與之前相同的客戶端,但on change事件並未插入,並從所選人員的數據庫中選擇信息。由於PHP下拉粘貼並提交表格
session_start();
$current = isset($_SESSION['ClientNamefour']) ? $_SESSION['ClientNamefour'] : 0;
$options4="";
while ($row = mysql_fetch_array($result)) {
$id=$row["Client_Code"];
$thing=$row["Client_Full_Name"];
$value="$id, $thing";
// insert SELECTED="SELECTED" if the current $id matches $current
$options4.="<OPTION VALUE=\"$value\" ".($id == $current ? ' SELECTED="SELECTED"' : '').">".$thing;
}
?>
<FORM name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<SELECT NAME="ClientNamefour" OnChange="this.form.submit()">
<OPTION VALUE=0>Client
<?php echo $options4?>
</SELECT>
</FORM>
session_start();
// Do the redirect
$_SESSION['ClientNamefour'] = $_POST['txtclientcode'];
header("Location: http://endeavor/php/financialoasistest.php");
重定向也是在HTML內容輸出用戶代理之後。 – 2010-01-18 20:19:56
session_start()的原因是兩次,因爲代碼駐留在兩個不同的頁面上。一個流程頁面,一個是實際的網站。 POST確實存在於頁面上。如何使onchange在會話返回時工作? – Eric 2010-01-18 20:20:55
如果出現這種情況,您需要將上面的代碼重新格式化爲兩段,並添加(相關的)缺失位 - 很難分辨出當前的情況,並且無法調試我們無法看到的代碼。 :-) – 2010-01-18 20:25:04