表单提交怪异行为

时间:2018-08-13 21:18:23

标签: php html mysql forms submit

<?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">&nbsp;
            <input type="text" name="name" placeholder="Name">&nbsp;
            <input type="text" name="email" placeholder="Email">&nbsp;
            <input type="text" name="phone" placeholder="Phone">&nbsp;
            <input type="text" name="circle" placeholder="Circle">&nbsp;
            <input type="text" name="ssa" placeholder="SSA">&nbsp;
            <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="#">&laquo;</a> <a class="active" href="#">1</a> <a href="#">2</a> <a href="#">3</a> <a href="#">4</a> <a href="#">&raquo;</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>

上面的代码应该将表格中填写的数据插入到DB中。它确实做到了,但是有时候只是奇怪。

就像我试图从2个小时开始使用chrome插入数据一样,但它不会这样做。突然,我对IE做了同样的事情,然后插入了。我以为可能与浏览器兼容,但是当我再次尝试使用IE时,它在执行一次后便停止了插入。

1 个答案:

答案 0 :(得分:1)

您不是要检查执行是否正确。

更改:

$stmt->execute();
if (!$stmt) {
    ...
}

收件人:

if (!$stmt->execute()) {
    ...
}