发布' SELECT'值得下一页PHP

时间:2013-09-18 16:05:13

标签: php post

以下是表单代码:

<?php
$con=mysqli_connect("localhost","user","pass","db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT ID, NAME FROM b_sonet_group ORDER BY ID DESC");


echo "<form class='form-vertical login-form' action='step-2.php' method='POST'>";

echo "<h4 class='form-title'>Step One: Choose Your Project</h4><div class='control-group'><div class='controls'>";              

echo "<select>";
echo "<option value=''>Choose Your Project</option>";

while($row = mysqli_fetch_array($result))

  {
  echo "<option name='ID' value='" . $row['ID'] . "'>" . $row['NAME'] . "</option>";
  }
  echo "</select>";

  echo "</div></div>";

  echo "<div class='form-actions'><button type='submit' name='submit' class='btn green pull-right'>Proceed to Step Two <i class='m-icon-swapright m-icon-white'></i></button></div></form>";


mysqli_close($con);
?>

我需要在第2页上从上一页的表单中检索值ID,以及如何打印它以便检查它是否是正确的ID?

简单我知道,但我的大脑已经收拾好并回家了。

2 个答案:

答案 0 :(得分:3)

您需要将select更改为

echo "<select name=\"project\">";

在第二页上,您可以使用

获取值
echo $_POST['project'];

答案 1 :(得分:0)

您需要将名称从选项移动到您的选择。然后回显$ _POST ['id'];