php - 表单提交奇怪的行为
问题描述
<?php
require_once("./include/membersite_config.php");
if(!$fgmembersite->CheckLogin())
{
$fgmembersite->RedirectToURL("index.php");
exit;
}
include 'header.php';
include './include/sql/connect.php';
if(isset($_POST['submit']))
{
$insert = "INSERT INTO `customers`(`bb_id`, `name`, `email`, `phone`, `circle`, `ssa`, `sdca`) VALUES (?,?,?,?,?,?,?)";
$stmt = mysqli_prepare($connect, $insert);
$stmt->bind_param('sssisss', $_POST['bb_id'],$_POST['name'],$_POST['email'],$_POST['phone'],$_POST['circle'],$_POST['ssa'],$_POST['sdca']);
$stmt->execute();
if (!$stmt)
{
printf("Error: %s\n", mysqli_error($connect));
exit();
}
}
$cust = "SELECT * FROM `customers`";
$qry = mysqli_query($connect,$cust);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Customers</title>
<!--link rel="stylesheet" type="text/css" href="style/fg_membersite.css"-->
<link rel="stylesheet" type="text/css" href="style/tableview.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<br>
<div id='tableview'>
<div class='ext-box'>
<form action="" method="post">
<input type="text" name="bb_id" placeholder="Broadband ID">
<input type="text" name="name" placeholder="Name">
<input type="text" name="email" placeholder="Email">
<input type="text" name="phone" placeholder="Phone">
<input type="text" name="circle" placeholder="Circle">
<input type="text" name="ssa" placeholder="SSA">
<input type="text" name="sdca" placeholder="SDCA"><br><br>
<input type="submit" name="searchsubmit" value="Search Records">
<input type="submit" name="submit" value="Update Records">
</form>
</div>
<br><br><br>
</div>
<table class="blueTable">
<thead>
<tr>
<th>Broadband ID</th>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Circle</th>
<th>SSA</th>
<th>SDCA</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="7">
<div class="links"><a href="#">«</a> <a class="active" href="#">1</a> <a href="#">2</a> <a href="#">3</a> <a href="#">4</a> <a href="#">»</a></div>
</td>
</tr>
</tfoot>
<tbody>
<?php while($row = mysqli_fetch_array($qry)):?>
<tr>
<td><?php echo $row['bb_id'];?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['email'];?></td>
<td><?php echo $row['phone'];?></td>
<td><?php echo $row['circle'];?></td>
<td><?php echo $row['ssa'];?></td>
<td><?php echo $row['sdca'];?></td>
</tr>
<?php endwhile;?>
</tbody>
</table>
</body>
</html>
上面的代码应该将表单中填写的数据插入到数据库中。它确实做到了,但奇怪的只是有时。
就像我尝试使用 chrome 插入数据 2 小时以来,但它不会这样做。突然间,我用 IE 做了同样的事情,它接受了插入。我想也许是浏览器兼容性,但是当我再次尝试使用 IE 时,它在执行一次后停止插入。
解决方案
您没有检查执行是否正确成功。
改变:
$stmt->execute();
if (!$stmt) {
...
}
至:
if (!$stmt->execute()) {
...
}
推荐阅读
- spring-boot - Jhipster 连接到 docker 中的 Mysql 数据库
- c# - 如何在 Asp.Net Core 3.1 中为现有 HttpContext 用户保留新添加的声明
- android - 在连接了两部安卓手机的主机上,无法从线程中的脚本同时在两部手机上运行 adb 命令
- python - Kedro 可以创建圆形图层吗
- flutter - Flutter:为什么键盘的文本类型在 iOS 上的数字键盘上没有改变?
- powerbi - 带有 where 子句对 DAX 表达式的子查询的 SQL 语句
- wordpress - 如何更改 WooCommerce 我的帐户下载区域中的文本?
- java - 如何在单独的 Java 类中存储和检索 WebElements - Selenium
- javascript - unity3d webgl 在选项卡或浏览器不活动时静音
- firebase - firebase 函数配置 - 删除数据