我在第88行收到以下错误,对于我一生,我无法弄清原因。我目前正在尝试在讲话时解决问题,但也认为发帖也是一个好办法。
错误是:
[2019年5月10日09:42:13 UTC] PHP致命错误:未捕获错误:在C:\ inetpub \ wwwroot \ SupportDesk \ php \ Add_New_Engineer.php:88中调用成员函数prepare() 堆栈跟踪: 0 C:\ inetpub \ wwwroot \ SupportDesk \ php \ Add_New_Engineer.php(5):create_eng() 1 {main}在第88行的C:\ inetpub \ wwwroot \ SupportDesk \ php \ Add_New_Engineer.php中抛出
代码:
Function create_eng(){
global $msgID;
global $msg, $conn;
$msgID = 0;
//Get POST from submit
$eng_name = $_POST['EngineersName'];
//SQL Query
$sql_count = "select count(*) as num from [Engineers] where [Engineer] = :eng_name";
//Query SQL Statement
$stmt = $conn->prepare($sql_count);
$stmt->bindValue(':eng_name', $eng_name);
//Execute SQL Statement
$stmt->execute();
$results=$stmt->fetchAll(PDO::FETCH_ASSOC);
//fetchAll(PDO::FETCH_ASSOC);
If($results['num'] > 0){
echo $msg = "Engineer $eng_name exist's in the database";
$msgID = 1;
}else{
$sql_insert = "insert into [Engineers](Engineer) values '$eng_name'";
//Prepare SQL Statement
$stmt = $conn->Prepare($sql_insert);
//Execute SQL Statement
$stmt->execute();
$results=$stmt->fetchAll(PDO::FETCH_ASSOC);
echo $msg = "Engineer $eng_name added to the database";
$msgID = 2;
}
}