Php 使用列表值更新mysql表

Php 使用列表值更新mysql表,php,Php,我有一个表单,可以将mysql表中的数据提取到表单中,每一行都有一个菜单可供选择一个值,我想在单击“全部应用”按钮时,用为每一行选择的每个值更新mysql,但根本不起作用。这是我的代码 <td><form id="main" name="main" method="post" action="setProjectStatus.php" onsubmit="return validateMain();"> <table width="100%" cells

我有一个表单,可以将mysql表中的数据提取到表单中,每一行都有一个菜单可供选择一个值,我想在单击“全部应用”按钮时,用为每一行选择的每个值更新mysql,但根本不起作用。这是我的代码

<td><form id="main" name="main" method="post" action="setProjectStatus.php" onsubmit="return validateMain();">
      <table width="100%" cellspacing="1" cellpadding="1">
        <tr>
          <td width="35%" rowspan="3"><img src="../img/project.jpg" alt="Comp Sci Stud" width="325" height="199" border="2" /></td>
          <td width="65%" height="42" colspan="2"><table width="94%" cellpadding="1" cellspacing="1" class="main_table">
            <tr class="table_title">
              <td width="100%" class="table_title">Set Project Status. </td>
              </tr>
            <tr>
              <td height="26">&nbsp;</td>
              </tr>
            <tr>
              <td height="26"><table width="100%" cellspacing="1" cellpadding="1">
                <tr class="table_head">
                  <td width="2%" height="35"><div align="center"></div></td>
                  <td width="26%" height="35"><div align="center">Student Name</div></td>
                  <td colspan="2"><div align="center">Project</div></td>
                  <td width="19%"><div align="center">Status</div></td>
                </tr>
<?php
 session_start();
 $username = $_SESSION['username'];

 require_once("mysqlConnect.php"); 

//
$sql="SELECT * FROM spms_Student";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

echo "There are $count projects to be undertaken.";
while($rows=mysql_fetch_array($result)){
//
$query = "SELECT name FROM spms_systemUser WHERE userId = '".$rows[0]."'";
$result1 = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result1);
$name = $row[0];
?>

                <tr>
                  <td height="25" align="center">&nbsp;</td>
                  <td align="center"><?php echo $name; ?></td>
                  <td colspan="2" align="center"><?php echo $rows[1]; ?></td>
                  <td align="center"><label>
                    <select name="select" class="form_field_100px_select">
                      <option value="Pending" selected="selected">Pending</option>
                      <option value="Approved">Approved</option>
                      <option value="Disapproved">Disapproved</option>
                    </select>
                  </label></td>
                </tr>
<?php
}
?>
                <tr class="pager_bg">
                  <td height="35">&nbsp;</td>
                  <td>&nbsp;</td>
                  <td width="37%" align="right"><input name="done" type="button" id="done" value="Done" onclick="window.location='../coordinatorMenu.html'" /></td>
                  <td width="16%"><label>
                    <input name="approveAll" type="submit" id="approveAll" value="Approve All" />
                  </label></td>
                  <td><input name="apply" type="submit" id="apply" value="Apply To All" /></td>
                </tr>
<?php
mysql_close();
?>
              </table></td>
            </tr>
          </table></td>
          </tr>
        <tr>
          <td colspan="2">&nbsp;</td>
          </tr>

        <tr>
          <td colspan="2"><label></label>            <label></label></td>
          </tr>
      </table>
    </form></td>

设置项目状态。
学名
项目
地位

您试图重用MySQL连接,同时仍然保留第一次查询的结果集。您需要为内部循环查询创建第二个连接。更好的方法可能是使用连接重写查询,但我不能在不了解模式的情况下确定。

setProjectStatus.php中的代码是什么?这会很有帮助。。我们无法真正帮助您,因为似乎所有的魔法都在另一页上发生;)此页正在调用自身,并且只有顶部的代码。。。if(isset($_POST['approveAll']){//connect并选择一个数据库require_once(“mysqlConnect.php”);$sql=“UPDATE tablename SET projectStatus='Approved'”;mysql_query($sql);}