所以我有一个 foreach 循环来在我的数据库中插入值,我想在循环结束时显示警报并检查插入是否成功我有这个if (isset($_POST['alter'])) { # code... foreach ($_POST['id'] as $key => $id) { $array1 = $_POST['name'][$key]; $array2 = $_POST['surname'][$key]; $array3 = $_POST['tel'][$key]; $array4 = $_POST['email'][$key]; $query = $link -> prepare("UPDATE table SET name = ? , surname = ? , tel = ? , email = ? WHERE id = ?;"); $query -> bind_param('sssss',$array1,$array2,$array3,$array4,$id); $s = $query -> execute(); $query -> close(); if ($s==1){ ?><div class="alert alert-success"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> <strong>SUCCESS!</strong> </div><?php } else { ?><div class="alert alert-danger"> <button type="button" class="close" data-dismiss="alert" aria- hidden="true">×</button> <strong>ERROR.</strong> </div><?php } }}但这会在页面中多次显示警报我怎样才能让它只显示一个警报?
1 回答
- 1 回答
- 0 关注
- 115 浏览
添加回答
举报
0/150
提交
取消