我正在尝试使用邮递员测试api,每次我尝试注册时我都会收到“意外的e”。 真的不知道发生了什么 这是我的代码:
$app->post('/signup', function() {
$app = \Slim\Slim::getInstance();
$name = $app->request()->post('name');
$email = $app->request()->post('email');
$pass = $app->request()->post('pass');
$app->response->setStatus(200);
$app->response()->headers->set('Content-Type', 'application/json');
try
{
$db = getDB();
$sth = $db->prepare("select count(*) as count from user WHERE email=:email");
$sth->bindParam(':email', $email, PDO::PARAM_INT);
$sth->execute();
$row = $sth->fetch();
if($row['count']>0){
$output = array(
'status'=>"0",
'operation'=>"student already registered"
);
echo json_encode($output);
$db = null;
return;
}
else{
//我尝试在我的数据库中插入值。
$sth = $db->prepare("INSERT INTO user (name, email,password)
VALUES(:name,:email,:pass)");
$sth->bindParam(':name', $name, PDO::PARAM_INT);
$sth->bindParam(':email', $email, PDO::PARAM_INT);
$sth->bindParam(':pass', $pass, PDO::PARAM_INT);
$sth->execute();
$output = array(
'status'=>"1",
'operation'=>"success"
);
echo json_encode($output);
$db = null;
return;
}
}
catch(Exception $ex){
echo $ex;
}
});