微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我的数据库中没有输入 PHP 准备好的语句

如何解决我的数据库中没有输入 PHP 准备好的语句

我正在尝试创建一个简单的网站,其中有人以 html 形式输入一些信息,并使用 PHP 准备好的语句将信息插入到我的数据库中。虽然我已经检查了很多次我的输入是正确的,并且我没有遇到 sql 错误,但数据没有被插入到我的数据库中。谁能帮忙找出哪里出了问题?

<?PHP
error_reporting(E_ALL);
ini_set('display_errors',1);
$dbServername="localhost";
$dbUsername="root";
$dbPassword="";
$dbname="console";

$conn=MysqLi_connect($dbServername,$dbUsername,$dbPassword,$dbname);

if(isset($_POST['submit'])){
    $last=$_POST['lastname'];
    $first=$_POST['firstname'];
    $tel1=$_POST['tel1'];
    if(empty($_POST['tel2'])){ 
        $tel2=null;
    }else{
        $tel2=$_POST['tel2'];
    }
    $address=$_POST['ad'];
    $postcode=$_POST['postcode'];
    $city=$_POST['city'];
    $email=$_POST['email'];
    $job=$_POST['job'];

    $sql = "INSERT INTO customers (tel1,tel2,postcode,lastname,firstname,ad,city,email,job) VALUES (?,?,?)";
    $stmt=MysqLi_stmt_init($conn);//create prepared statement
    if (!MysqLi_stmt_prepare($stmt,$sql)){  //check if the prepared statement was succesfully prepared
        header("Location: ../necustomer.PHP?error=sqlerror");
        exit();
    }else{
  MysqLi_stmt_bind_param($stmt,"iiissssss",$tel1,$tel2,$postcode,$last,$first,$address,$city,$email,$job); //bind the parameters with the placeholders
    MysqLi_stmt_execute($stmt);
    }
     header("Location: ../necustomer.PHP?signup=success");

}else{
header("Location: ../necustomer.PHP");
  }

这是我的 PHP 文件

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。