我做了一个简单的表格,将数据存储在POSTGRESQL中。运行代码时,我收到此错误消息
致命错误:未捕获错误:在C:\ xampp \ htdocs \ html \ insert.php:19中的资源上调用成员函数prepare()堆栈跟踪:#0 {main}抛出在C:\ xampp \ htdocs中\ html \ insert.php,第19行
这是表单的HTML代码
<!DOCTYPE html>
<html>
<head>
<title>Register Employee</title>
</head>
<body>
<form action="insert.php" method="POST">
<table>
<tr>
<td>
Emp Code:
</td>
<td>
<input type="text" name="ecode" required>
<td>
Name:
</td>
<td>
<input type="text" name="name" required>
</td>
<td>
DOB:
</td>
<td>
<input type="text" name="dob">
</td>
<td>
Phone:
</td>
<td>
<input type="text" name="phone">
</td>
<td>
Alt Number:
</td>
<td>
<input type="text" name="alt">
</td>
<td>
Email:
</td>
<td>
<input type="text" name="email" required>
</td>
<td>
Address:
</td>
<td>
<input type="text" name="address">
</td>
<td>
City:
</td>
<td>
<input type="text" name="city">
</td>
<td>
State:
</td>
<td>
<input type="text" name="state">
</td>
<td>
Designation:
</td>
<td>
<input type="text" name="designation" required>
</td> <td>
Category:
</td>
<td>
<input type="text" name="category">
</td>
<td>
Specialty:
</td>
<td>
<input type="text" name="speciality">
</td>
</tr>
<tr>
<td>
<input type="submit" value="submit" name="">
</td>
</tr>
</table>
</form>
</body>
</html>
这是PHP代码
<?php
$name= $_POST['name'];
$phone= $_POST['phone'];
$dob= $_POST['dob'];
$ecode= $_POST['ecode'];
$designation= $_POST['designation'];
$speciality= $_POST['speciality'];
$category= $_POST['category'];
$alt= $_POST['alt'];
$address= $_POST['address'];
$city= $_POST['city'];
$state= $_POST['state'];
if(!empty($name)|| !empty($ecode)|| !empty($designation)|| !empty($speciality)){
$con=pg_connect("host=localhost dbname=Hospital_Users user=postgres password=aykai");
if (!$con) {
echo "Not Connected";
}
else {
$SELECT = "SELECT ecode from employee_master Where ecode= ? Limit 1";
$INSERT= "INSERT Into employee_master (name, phone, dob, ecode, designation, speciality, category, alt, address, city, state) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
//prepare statement
$stmt= $con->prepare($SELECT);
$stmt->bind_param("s", $ecode);
$stmt->execute();
$stmt->bind_result($ecode);
$stmt->store_result();
$rnum= $stmt->num_rows;
if($rnum==0){
$stmt->close();
$stmt = $con->prepare($INSERT);
$stmt->bind_param("sisssssisss", $name, $phone, $dob, $ecode, $designation, $speciality, $category, $alt, $address, $city, $state);
$stmt->execute();
echo "Added Successfully";
}
else{
echo "User Already exist with this emp code";
}
$stmt->close();
$con->close();
}
}
else{
echo "Please fill the required fields";
die();
}