我已经从html表单中获得了我的价值......收到的价值完全正确..但BIND_PARAM()的问题与准备好的声明?我可以使用php 7.0.1版本
<?php
if(isset($_POST['submit']))
{
if(empty(($_POST['fname'])) && empty(($_POST['lname'])) && empty(($_POST['dg'])) )
{
header("Location:view.html/form.html");
}
else
{
$f_name=addslashes($_POST['fname']);
$l_name=addslashes($_POST['lname']);
$post=addslashes($_POST['dg']);
}
//----------------connection to database using Pdo------------------
$hostname="localhost";
$uname="root";
$password="";
$database_name="test";
$conn= new mysqli($hostname,$uname,$password) or die("cannot connect to database Mysql");
$stm=$conn->prepare("insert into s_detail(F_Name,L_Name,Designation) values(?,?,?)");
$stm->bind_param("sss",$f_name,$l_name,$post);
//set parameter and execute
$f_name=addslashes($_POST['fname']);
$l_name=addslashes($_POST['lname']);
$post=addslashes($_POST['dg']);
if($stm->execute())
{
$stm->close();
echo "data is inserted successfully";
}
else
{
echo "failed to insert";
}
}
else
{
echo "Don't be oversmart with me";
}
?>
错误是......
Fatal error: Uncaught Error: Call to a member function bind_param() on boolean in C:\xampp_7\htdocs\oops in php\oops.php:24 Stack trace: #0 {main} thrown in C:\xampp_7\htdocs\oops in php\oops.php on line 24
Plz帮助.....
答案 0 :(得分:0)
您还需要添加数据库参数。那个缺失
$conn= new mysqli($hostname,$uname,$password,$database_name);
作为一种习惯,请务必检查您是否已成功连接到目标数据库
if($conn ==== false) {
die('error on connecting to database '.$conn->connect_error);
}