问题描述
我正在尝试创建一个简单的网站,其中有人以 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");
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)