选择不传递值的选项

时间:2014-10-10 09:49:08

标签: php html

我的选择选项未传递值。我不知道为什么这不起作用任何帮助都会受到赞赏,但我不知道发生了什么。

HTML / PHP

if(isset($_POST['submit'])){ $Name = isset($_POST['name']) ? trim($_POST['name']) :''; echo "
<a href='index.php'>
  <-- Your Home Page</a>
    </br>
    </br>"; echo "
    <table border='1'>
      <form action='' method='post'>
        <tr>
          <th>Name</th>
          <th>Car</th>
          <th>Night</th>
          <th>Siteid</th>
          <th>Date</th>
          <th>LHA</th>
          <th>AAS</th>
          <th>LS</th>
          <th>Update</th>
        </tr>"; $sql = "SELECT * FROM data WHERE Name = '$Name' ORDER BY Date"; $sth = $pdo->query($sql); while($row = $sth->fetch()) { $Car = $row['Car']; echo "
        <form action='' method='post'>"; echo "
          <tr>"; echo "
            <td>" . $row['Name']. "</td>"; echo "
            <td>
              <input type='text' name='Car' placeholder='".$row[' Car ']."' value=''>
            </td>"; echo "
            <td>
              <input type='text' name='Car' placeholder='".$row[' Night ']."' value=''>
            </td>"; echo "
            <td>
              <input type='text' name='Car' placeholder='".$row[' Siteid ']."' value=''>
            </td>"; echo "
            <td>
              <input type='text' name='Car' placeholder='".$row[' Date ']."' value=''>
            </td>"; echo "
            <td>
              <input type='text' name='Car' placeholder='".$row[' LHA ']."' value=''>
            </td>"; echo "
            <td>
              <input type='text' name='Car' placeholder='".$row[' AAS ']."' value=''>
            </td>"; echo "
            <td>
              <input type='text' name='Car' placeholder='".$row[' LS ']."' value=''>
            </td>"; echo "
            <input type='hidden' name='PID' value='".$row[' PID ']."' />"; echo "
            <td>
              <input type='submit' name='submit' value='".$row[' PID ']."' />
            </td>"; echo "</tr>"; echo "</form>"; } echo "</table>"; $pdo = NuLL; }Else{ Echo "Pick a user"; } ?>

HTML表单

    <form action="" method="POST">
      <select name="name" id="name">
        <?php foreach ($data as $row): ?>
        <option value="<?=$row['user_id']?>">
          <?=$row[ "user_name"]?>
        </option>
        <?php endforeach ?>
      </select>
      <input type="submit" value="submit">
    </form>

4 个答案:

答案 0 :(得分:1)

因为你的选项标签没有价值

试试这个

<form action="" method="post">
<select name="name" id="name">
<?php foreach ($data as $row): ?>
    <option value="<?php=$row["user_name"]?>"> <?php echo $row["user_name"]?></option>
<?php endforeach ?>
</select>
<input type="submit" value="submit">
</form>

使用这样的php标签更好,而不是你现在使用的

$Name = isset($_POST['name']) ? trim($_POST['name']) :'';
<?php echo $row["user_name"]?>// i dont know why you have this line here

并显示结果

<?php echo $Name;?>

答案 1 :(得分:0)

请使用这种方式:

<option value="<?=$row["user_name"]?>"> <?=$row["user_name"]?></option>

答案 2 :(得分:0)

您必须将值设置为发布。像这样:

<option value="<?=$row["user_name"]?>"> <?=$row["user_name"]?></option>

答案 3 :(得分:0)

如果要使用<option>标记内的值,则必须删除属性value=""。你的行成了:

<option><?=$row["user_name"]?></option>

属性value="something"非常有用,当您想要显示一些&#34;人类可读的&#34;信息,但发送更适用于您的系统的东西。

通常,您可以显示user_name(放置在标记内的内容),并像这样发送user_id:

<option value="<?=$row['user_id']?>"><?=$row["user_name"]?></option>