dongyouzhui1969 2012-07-02 08:54
浏览 52
已采纳

列表框将变量值从MySQL传递给数组

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

This above code is update form that query from database. All variable are ok except group

   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();
    }

This is use for get data from submit button. I try to use print_r to get all value in each array. They all have except group. Can I fix this issue?

    Array ( [std_id] => 52211001 [name] => testname2 [surname] => testsurname1 [group] => [email] => tes21@test.com ) 
    Array ( [std_id] => 52211001 [name] => testname2 [surname] => testsurname1 [group] => 0 [email] => tes21@test.com )

This is an output

  • 写回答

1条回答 默认 最新

  • drhozgt6007 2012-07-02 09:05
    关注

    Why do you cast to int? And the line:

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

    should be:

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号