dousui7410 2016-07-27 15:11
浏览 64
已采纳

提交后通过while循环提取的最后一个值[关闭]

Whenever I click submit the last value of email fetched is always posted. what should I do to post the current email, and how to post the current email value with the selected status from each table row

<form action="" method="post">
<table>
<tbody>
<?php
while($row=mysqli_fetch_assoc($query))
{
echo '
<tr>
<td style="text-align:center;">
<select name="statuss">
<option selected="selected" disabled="disabled">Select Status</option>
<option value="1">Submitted</option>
<option value="2">Accepted</option>
<option value="3">Questionnaire</option>
<option value="4">Interview</option>
</select>
<input type="text" name="email" value="'.$row['email'].'">
<input type="submit" value="Update" name="submit" class="btn btn-primary">
</td>
</tr>';
}
?>
</tbody>
</table>

</form>
<?php
if(isset($_POST['submit']))
{
$email=(isset($_POST['email']) ? $_POST['email'] : '');
$statuss=(isset($_POST['statuss']) ? $_POST['statuss'] : '');
$sql="update status SET personal_stylist = '$statuss' where email='$email'";
$query=mysqli_query($connection, $sql);
}
?>
  • 写回答

1条回答 默认 最新

  • douhuireng4407 2016-07-27 15:31
    关注

    Among a number of other problems with the code (which you drastically change with every edit, so it's hard to keep up), logically the form has no way of knowing which values you intuitively intended to post.

    Simplified, you have this structure:

    <form>
      <table>
        <row>a bunch of fields</row>
        <row>a bunch of fields</row>
        <row>a bunch of fields</row>
      </table>
    </form>
    

    However, each row has the same fields. So when the form posts, it can't know which fields you were looking at when you submitted the form. All it can do is package them all up into one form POST. And as it does so, each time it encounters a field by the same name, the new field will overwrite the previous field.

    Move your <form> to inside the rows. Simplified again, the structure would be more like this:

    <table>
      <row>
        <form>a bunch of fields</form>
      </row>
      <row>
        <form>a bunch of fields</form>
      </row>
      <row>
        <form>a bunch of fields</form>
      </row>
    </table>
    

    More specifically, make the <form> a descendant of the <td>:

    while($row=mysqli_fetch_assoc($query))
    {
      echo '
      <tr>
        <td style="text-align:center;">
          <form>
            your form
          </form>
        </td>
      </tr>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图