2015-11-05 40 views
1

我有下拉編輯表單。 所有ISBN記錄都列在下拉列表中。用戶將選擇他想要更新的ISBN。現在如何獲得該用戶選擇哪個ISBN記錄? 我的下拉菜單的邏輯如下:如何獲取在其他頁面上選擇的值?

function update() 
{ 
$select_query="Select ISBN from book"; 
$select_query_run = mysql_query($select_query); 
echo"<form method='post' action='update.php'><center>Select ISBN you want to Update: "; 
echo "<select name='isbn' id='isbn'>"; 
while ($select_query_array=mysql_fetch_array($select_query_run)) 
{ 
    echo "<option value='' >".htmlspecialchars($select_query_array["ISBN"])." </option>"; 
} 
echo "</select>"; 
echo '<br><br><br><input type="submit" value="Update"></center></form>'; 
} After selecting ISBN the user will be navigated to update php page whoch is as follow: 

<?php 
$isbn=$_POST['isbn']; 
echo "ISBN Selected: ".$isbn; 
?> 

更新頁面的輸出: ISBN選擇:

回答

0

爲此,您應該試試這個:

echo "<option value='' >".htmlspecialchars($select_query_array["ISBN"])." </option>"; 

取而代之的是:

echo "<option value='".htmlspecialchars($select_query_array['ISBN'])."' >".htmlspecialchars($select_query_array["ISBN"])." </option>"; 
1

因爲你的價值是在選擇框中

echo "<option value='' >".htmlspecialchars($select_query_array["ISBN"])." </option>"; 
        ^^ 

空則需要在增加價值您的選擇框

echo "<option value='".htmlspecialchars($select_query_array['ISBN'])."' >".htmlspecialchars($select_query_array["ISBN"])." </option>"; 
+0

並設置屬性'selected'到''

+1

將由用戶選擇不是他 – achecopar

+0

是的,它會根據用戶選擇 – Saty

相關問題