此脚本可能有什么问题?
<?php
// json response array
$response = array("error" => FALSE);
if (isset($_POST['amountApplied']) && isset($_POST['mop']) && isset($_POST['term']) && isset($_POST['lastname']) && isset($_POST['firstname']) && isset($_POST['middlename']) && isset($_POST['birthdate']) && isset($_POST['age']) && isset($_POST['sex']) && isset($_POST['status']) && isset($_POST['marriageDate']) && isset($_POST['noChildren']) && isset($_POST['nationality']) && isset($_POST['acr']) && isset($_POST['address']) && isset($_POST['cityMunicipality']) && isset($_POST['province']) && isset($_POST['telNo']) && isset($_POST['years']) && isset($_POST['offAddress']) && isset($_POST['offCityMunicipality']) && isset($_POST['offProvince']) && isset($_POST['offTelNo']) && isset($_POST['offYears']) && isset($_POST['busAddress']) && isset($_POST['busCityMunicipality']) && isset($_POST['busProvince']) && isset($_POST['busTelNo']) && isset($_POST['busYears']) && isset($_POST['productServiceOffered'])) {
// receiving the post params
$amountApplied = $_POST['amountApplied'];
$mop = $_POST['mop'];
$term = $_POST['term'];
$lastname = $_POST['lastname'];
$firstname = $_POST['firstname'];
$middlename = $_POST['middlename'];
$birthdate = $_POST['birthdate'];
$age = $_POST['age'];
$sex = $_POST['sex'];
$status = $_POST['status'];
$marriageDate = $_POST['marriageDate'];
$noChildren = $_POST['noChildren'];
$nationality = $_POST['nationality'];
$acr = $_POST['acr'];
$address = $_POST['address'];
$cityMunicipality = $_POST['cityMunicipality'];
$province = $_POST['province'];
$telNo = $_POST['telNo'];
$years = $_POST['years'];
$offAddress = $_POST['offAddress'];
$offCityMunicipality = $_POST['offCityMunicipality'];
$offProvince = $_POST['offProvince'];
$offTelNo = $_POST['offTelNo'];
$offYears = $_POST['offYears'];
$busAddress = $_POST['busAddress'];
$busCityMunicipality = $_POST['busCityMunicipality'];
$busProvince = $_POST['busProvince'];
$busTelNo = $_POST['busTelNo'];
$busYears = $_POST['busYears'];
$productServiceOffered = $_POST['productServiceOffered'];
require 'include/DB_Connect.php';
$db = new DB_Connect();
$result = $db->storeClient($amountApplied, $mop, $term, $lastname, $firstname, $middlename, $birthdate, $age, $sex, $status, $marriageDate, $noChildren, $nationality, $acr, $address, $cityMunicipality, $province, $telNo, $years, $offAddress, $offCityMunicipality, $offProvince, $offTelNo, $offYears, $busAddress, $busCityMunicipality, $busProvince, $busTelNo, $busYears, $productServiceOffered);
if ($result) {
// user stored successfully
$response["error"] = FALSE;
$response["amountApplied"] = $result["amountApplied"];
$response["mop"] = $result["mop"];
$response["term"] = $result["term"];
$response["lastname"] = $result["lastname"];
$response["firstname"] = $result["firstname"];
$response["middlename"] = $result["middlename"];
$response["birthdate"] = $result["birthdate"];
$response["age"] = $result["age"];
$response["sex"] = $result["sex"];
$response["status"] = $result["status"];
$response["marriageDate"] = $result["marriageDate"];
$response["noChildren"] = $result["noChildren"];
$response["nationality"] = $result["nationality"];
$response["acr"] = $result["acr"];
$response["address"] = $result["address"];
$response["cityMunicipality"] = $result["cityMunicipality"];
$response["province"] = $result["province"];
$response["telNo"] = $result["telNo"];
$response["years"] = $result["years"];
$response["offAddress"] = $result["offAddress"];
$response["offCityMunicipality"] = $result["offCityMunicipality"];
$response["offProvince"] = $result["offProvince"];
$response["offTelNo"] = $result["offTelNo"];
$response["offYears"] = $result["offYears"];
$response["busAddress"] = $result["busAddress"];
$response["busCityMunicipality"] = $result["busCityMunicipality"];
$response["busProvince"] = $result["busProvince"];
$response["busTelNo"] = $result["busTelNo"];
$response["busYears"] = $result["busYears"];
$response["productServiceOffered"] = $result["productServiceOffered"];
$response["error_msg"] = "Application successfully made.";
echo json_encode($response);
} else {
// user failed to store
$response["error"] = TRUE;
$response["error_msg"] = "Oops! An error occurred.";
echo json_encode($response);
}
} else {
$response["error"] = TRUE;
$response["error_msg"] = "Required field(s) is missing.";
echo json_encode($response);
}
?>
错误:
致命错误:未捕获错误:调用未定义的方法 第44行上的DB_Connect :: storeClient()。
我无法真正分辨出脚本出了什么问题。我只是在教程中得到了这个脚本,并逐步研究了它。任何帮助,技巧和协助将不胜感激。预先感谢
这是DB_Connect
<?php
class DB_Connect {
private $conn;
// Connecting to database
public function connect() {
require 'include/Config.php';
// Connecting to mysql database
$this->conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
// return database handler
return $this->conn;
}
}
?>
答案 0 :(得分:0)
您仅实例化DB_Connect对象,但从未调用连接。
所以:
...
require 'include/DB_Connect.php';
$db = new DB_Connect();
$db->connect();
$result = $db->storeClient ...
这应该可以解决问题:)