السلام عليكم لدي كود مرفق لماذا عندما ادخل بيانات لاتظهر رسالة created بينما تظهر رسالة خطا رغم ادخالي صحيح
<?php
error_reporting(0);
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
header('Access-Control-Allow-Method: POST');
header('Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, x-requested-with ');
include('function.php');
$requestMethod=$_SERVER["REQUEST_METHOD"];
if($requestMethod=="POST")
{
$inputData=json_decode(file_get_contents("php://input"),true);
if(empty($inputData))
{
$storecustomer=stroecustomer($_POST);
}
else
{
$storecustomer=stroecustomer($inputData);
}
echo $stroecustomer;
}
else
{
$data=[
'status'=>405,
'message'=>$requestMethod.' Method Not Allowed',
];
header("HTTP/1.0 405 Method Not Allowed");
echo json_encode($data);
}
?>
ملف دوال
<?php
require '../inc/dbcon.php';
function error422($message)
{
$data=[
'status'=>422,
'message'=>$message ,
];
header("HTTP/1.0 422 Unprocessable Entity");
echo json_encode($data);
exit();
}
function stroecustomer($customerinput)
{
global $conn;
$name=mysqli_real_escape_string($conn,$customerinput['name']);
$email=mysqli_real_escape_string($conn,$customerinput['email']);
$phone=mysqli_real_escape_string($conn,$customerinput['phone']);
if(empty(trim($name)))
{
return error422('Enter your name');
}elseif(empty(trim($email)))
{
return error422('Enter your Email');
}
elseif(empty(trim($phone)))
{
return error422('Enter your phone');
}
else
{
$query="INSERT INTO users (name,email.phone) VALUES ('$name','$email','$phone') ";
$resault=mysqli_query($conn,$query);
if($resault)
{
$data = [
'status' => 201,
'message' => 'User Created Successfully',
];
header("HTTP/1.0 201 Created");
return json_encode($data);
}
else
{
$data = [
'status' => 500,
'message' => 'Internal Server Error',
];
header("HTTP/1.0 500 Internal Server Error");
return json_encode($data);
}
}
}
function getcustomerlist()
{
global $conn;
$query = "select *from users";
$query_run = mysqli_query($conn, $query);
if ($query_run) {
if(mysqli_num_rows($query_run)>0)
{
$res=mysqli_fetch_all($query_run, MYSQLI_ASSOC);
$data = [
'status' => 200,
'message' => 'User list Fetched Successfully ',
'data'=> $res
];
header("HTTP/1.0 200 OK");
return json_encode($data);
}
else
{
$data = [
'status' => 404,
'message' => 'NO User Found ',
];
header("HTTP/1.0 404 No User Found");
return json_encode($data);
}
} else {
$data = [
'status' => 500,
'message' => 'Internal Server Error',
];
header("HTTP/1.0 500 Internal Server Error");
return json_encode($data);
}
}
?>