2012-07-02 64 views
-1
<form action = "settings.php" method = "post"> 
Student ID*: 
<input type = "text" name = "std_id" value = "<?php echo $user_data['std_id'];?>"><br> 
Firstname*: 
<input type = "text" name = "name" value = "<?php echo $user_data['name'];?>"><br> 
Surname*: 
<input type = "text" name = "surname" value = "<?php echo $user_data['surname'];?>"><br> 
Group*: 
<select name = "group" id = "group"> 
    <option value="0"><-- Please Select Item --></option> 
    <?php 
    $show=mysql_query("SELECT * FROM room_group_options ORDER BY op_id"); 
    while ($array = mysql_fetch_array($show)) 
    { 
     $id = $array['id']; 
     $group = $array['group']; 
     echo "<option value = '$id'> $group </option>"; 
    }?> 
</select><br> 
Email*: 
<input type = "text" name = "email" value = "<?php echo $user_data['email'];?>"><br> 
<input type = "submit" name "update" value = "update"> 
</form> 

上面這段代碼是從數據庫中查詢的更新形式。除組列表框將MySQL中的變量值傳遞給數組

if(empty($_POST) === false && empty($error) === true) 
    { 
     $update_data = array(
      'std_id' => $_POST['std_id'], 
      'name' => $_POST['name'], 
      'surname' => $_POST['surname'], 
      'group' => (int)$_POST['group'], 
      'email' => $_POST['email'], 
     ); 

     print_r($_POST); 
        print_r($update_data); 

     die(); 
    } 

這是用於從提交按鈕中獲取數據。我嘗試使用print_r來獲取每個數組中的所有值。他們都有團隊。我能解決這個問題嗎?

Array ([std_id] => 52211001 [name] => testname2 [surname] => testsurname1 [group] => [email] => [email protected]) 
    Array ([std_id] => 52211001 [name] => testname2 [surname] => testsurname1 [group] => 0 [email] => [email protected]) 

這是一個輸出

+0

被取出,並在下拉框中(格式)中顯示的組名。 –

+0

也檢查值。他們只是數字嗎? – Samson

+0

感謝@radashk 全部解決:) –

回答

0

你爲什麼強制轉換爲int?併線:

echo "<option value = '$id'> $group </option>";

應該是:

echo '<option value = "'.$id.'">'. $group .'</option>';

+0

是的$ _POST拿起選項VALUE並傳遞給定義的頁面。我想問題是你沒有得到形式中的價值。我猜@radashk是對的。 –

+0

已經嘗試了你的代碼,仍然是這個錯誤。 –

+0

如果在