评估测试脚本语法错误意外标记时出错?

there was an error in evaluating the test script syntax error unexpected token?

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;
        }
    }

PDO 的 execute() 函数 returns true 成功,false 失败。

PDO's Execute() function

您通过在 createprovider 函数内的 if 语句中否定 this 来引入混淆。 所以你基本上有矛盾的 if 块,结果你的整体逻辑被打破了,但你的代码需要一些改变。

这应该可以正常工作:

$app->post(...
...
if ($res == 1) {
    $response["error"] = false;
    $response["message"] = "You are successfully registered";
    echoResponse(201, $response);
} else if ($res == 0) {
    $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);
}
...

然后里面 createprovider():

...
$stmt->close();
if ($result) {
    return 1;
} else {
    return 0;
}
...

另外,对于更 "RESTful" 的实现,您不应使用代码“2XX”来表示错误。