doubu8643 2016-10-20 15:07 采纳率: 100%
浏览 82
已采纳

无法获取HTML选择数据到POST.PHP

I have an input.php file with a form containing two types of lookup fields. One is populated from a series of <option> tags ($grade_1) and the other field is populated from a column in a database ($role_1). Both lookup fields display fine in the input.php form. I'm having trouble getting the user's selection based on database input ($role_1)into the post.php. I used ISSET as test code to see if I could get the count and data for $role_1. I can echo the Count ($nroles), but the echo of the data element ($role_1) doesn't display. The variable $grade_1 works fine. Here's part of the input form:

<?php $link = new mysqli("localhost","USER","PASSWORD", "DATABASE");
    if (mysqli_connect_errno())
    {   printf("Connect failed: %s
", mysqli_connect_error());
        exit();
    }
    if (!$link->set_charset("utf8")) 
    {   printf("Error loading character set utf8: %s
", $link->error);
        exit();
    }
    $role_sql = "SELECT role FROM lu_role";
    $role_result2 = mysqli_query($link, $role_sql) or die (mysqli_error($link));
    $options = "";
    while($row2 = mysqli_fetch_array($role_result2))
    {
        $options = $options."<option value=''>$row2[0]</option>";
    }
?>
<form action="post.php" method="post">
    <table class="table_600_reg">
      <tr>
        <td width="120">
         <select name="grade_1" style="background-color:#EFD381;">
            <option value="0">Choose Grade</option>
            <option value="1">First</option>
            <option value="2">Second</option>
            <option value="3">Third</option>
            <option value="4">Fourth</option>
            <option value="5">Fifth</option>
            <option value="6">Sixth</option>
            <option value="7">Seventh</option>
            <option value="8">Eighth</option>
          </select>
        </td>
        <td width="200" align="left">
            <select name="role_1" style="background-color:#EFD381;">
                <?php echo $options;?>
            </select>               
        </td>
      </tr>
    </table>
</form>

A snippet from the Post.PHP file is:

$link = new mysqli("localhost","USER","PASSWORD", "DATABASE");
  if (mysqli_connect_errno())
   {
   printf("Connect failed: %s
", mysqli_connect_error());
  exit();
}
//* change character set to utf8 */
//Print an error if utf8 can not be loaded
if (!$link->set_charset("utf8")) 
{
    printf("Error loading character set utf8: %s
", $link->error);
    exit();
}
$role_1 = mysqli_real_escape_string($link, $_POST[role_1]);
$grade_1 = mysqli_real_escape_string($link, $_POST[grade_1]);
if(!isset($role_1)) 
  {
    echo("<p>You didn't select any role_1!</p>
");
  } 
else
  {
    $nroles = count($role_1);
    echo("<p>You selected $nroles roles: ");
    for($i=0; $i < $nroles; $i++)
    {
      echo($role_1[$i] . " ");
    }
    echo("</p>");
    exit;
  }

Why can't I see the data from the $role_1 variable? Thanks for looking at this.

  • 写回答

1条回答 默认 最新

  • douluo5937 2016-10-20 15:31
    关注
    $options = $options."<option value=''>$row2[0]</option>";
    

    value is Empty String

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

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算