-2

这是来自数据库的页面显示表,每一行都有文本框,b_id 用于更新表。

$result2 = mysqli_query($con,"SELECT * FROM zahialga WHERE bid IN ($imp)");
    while($row = mysqli_fetch_array($result2))
      {
      echo "<tr>";
      echo "<td>" . $row['b_id'] . "</td>";
      echo "<td>" . $row['materials'] . "</td>";
      echo "<td>" . $row['num'] . "</td>";
      echo "<td> <input type='text' name='sh_num[]' maxlength='10'></td>";
      echo "</tr>";
      echo "<input type='hidden' name='b_id[]' value='" . $row['bid'] . "'>";
      }
      echo "</table>";
    echo "<input type='submit' value='Илгээх'/>";

这是更新页面。

$con=mysqli_connect("localhost","root","","login");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$sh_id_query = mysqli_query($con,"SELECT sh_id FROM zahialga order by bid desc limit 1");
$sh_id1 = $sh_id_query->fetch_object()->sh_id;
$sh_id2 = $sh_id1 + 1;
$count = count(array_filter($_POST["sh_num"]));
for($i=0;$i<$count;$i++)
{
$insert = mysqli_query($con,"UPDATE table SET 
                    sh_id='{$sh_id2}', 
                    sh_num='{$_POST['sh_num'][$i]}'
WHERE bid = '{$_POST['$b_id'][$i]}'");
}

这是getiingNotice: Undefined index: $b_id错误。我错过了什么?顺便说一句,对不起我的英语不好。

4

2 回答 2

1
$insert = mysqli_query($con,"UPDATE table SET 
                    sh_id='{$sh_id2}', 
                    sh_num='{$_POST['sh_num'][$i]}'
WHERE bid = '{$_POST['$b_id'][$i]}'");
//                    ^ additional $ sign here

应该

$insert = mysqli_query($con,"UPDATE table SET 
                    sh_id='{$sh_id2}', 
                    sh_num='{$_POST['sh_num'][$i]}'
WHERE bid = '{$_POST['b_id'][$i]}'");
于 2013-08-07T03:33:21.187 回答
1

不应该有 $ 符号:

$_POST['b_id'][$i]
于 2013-08-07T03:33:44.750 回答