Index.php
В этом сервисе я хочу вставить детали в базу данных методом POST, но это дает мне некоторую ошибку, поэтому, пожалуйста, помогите мне ее решить ..
Вот мой код -
app->post('/createprovider', function () use ($app) {
verifyRequiredParams(array('fullname', 'email', 'mobile', 'password','business_name', 'email_work', 'phone_work', 'address', 'latitude', 'longitude', 'category'));
$response = array();
$fullname = $app->request->post('fullname');
$email = $app->request->post('email');
$mobile = $app->request->post('mobile');
$password = $app->request->post('password');
$business_name = $app->request->post('business_name');
$email_work = $app->request->post('email_work');
$phone_work = $app->request->post('phone_work');
$address = $app->request->post('address');
$latitude = $app->request->post('latitude');
$longitude = $app->request->post('longitude');
$category = $app->request->post('category');
$db = new DbOperation();
$res = $db->createprovider($fullname, $email, $mobile, $password, $business_name, $email_work, $phone_work, $address, $latitude, $longitude, $category);
if ($res == 0) {
$response["error"] = false;
$response["message"] = "You are successfully registered";
echoResponse(201, $response);
} else if ($res == 1) {
$response["error"] = true;
$response["message"] = "Oops! An error occurred while registereing";
echoResponse(200, $response);
} else if ($res == 2) {
$response["error"] = true;
$response["message"] = "Sorry, this student already existed";
echoResponse(200, $response);
}
});
Это функция в dboperation.php
public function createprovider($fullname,$email,$mobile,$pass,$business_name,$email_work,$phone_work,$address,$latitude,$longitude, $category){
if (!$this->isProviderExists($email)) {
$password = md5($pass);
//$apikey = $this->generateApiKey();
$stmt = $this->con->prepare("INSERT INTO nesbaty_provider(fullname, email, mobile, password, business_name, email_work, phone_work, address, latitude, longitude, category) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssssssssss", $fullname, $email, $mobile, $password, $business_name, $email_work, $phone_work, $address, $latitude, $longitude, $category);
$result = $stmt->execute();
$stmt->close();
if ($result) {
return 0;
} else {
return 1;
}
} else {
return 2;
}
}