PHP mySQL UPDATE脚本不会执行

时间:2014-03-08 02:58:08

标签: php mysql

我无法理解为什么这不会被执行到mySQL数据库中? 一切都已设定,它所做的只是更新一些值。

    <?php
$con=mysqli_connect(This is filled.);
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

mysqli_query($con,"UPDATE `members` SET `rank`='$_POST[rank]' WHERE `id`='$_POST[id]'");


mysqli_close($con);
header("Location: index.php");
?>

继承人应该填充$ _POSTs

<form action="setrank.php" method="post">
User: 
  <select>
      <?php
  $result = mysqli_query($con,"SELECT * FROM members ORDER BY id");

while($row = mysqli_fetch_array($result))
  {
  echo "<option name='id' id='id' value='" . $row['id'] . "'>" . $row['username'] . " (" . $row['id'] . ")</option>";
  }
?>
  </select><br />
Set rank to: 
    <select><option name="rank" id="rank" value="0" >Guest.</option><option name="rank" id="rank" value="1" >Moderator.</option><option value="2" name="rank" id="rank">Administrator.</option><option value="3" name="rank" id="rank">Owner.</option></select>
<br /><input type="submit">
</form>

非常感谢您的帮助,我一直在使用小时。 :/

1 个答案:

答案 0 :(得分:1)

表单select元素定义不正确,在name中添加表单字段select box而不是选项请尝试这种方式

<select name="id"> 
 <option value="xyz">Name</option>
</select>