Bad string ? WHY


#1

$app->post(’/api/login’, function($request, $response) {

$email= $request->getParam(‘email’);
$pass= $request->getParam(‘pass’);
try
{
//get db object
$db = new db();
//connect
$db = $db->connect();
$sth = $db->prepare(“SELECT count(*) AS count FROM users WHERE email=:email AND password=:pass”);

$sth->bindParam(’:pass’, $pass);
$sth->bindParam(’:email’, $email);
$sth->execute();
$row = $sth->fetch();
if($row[‘count’]>0){
$output = array(
‘status’=>“1”,
‘login’=>“sucess”,
);
}
else{
$output = array(
‘status’=>“0”,
‘login’=>“fail”,
);
}
}
catch(Exception $ex){
$output = array(
‘status’=>“2”,
‘login’=>“error”,
);
}
// $object = (object) $output;
echo json_encode($output);
$db = null;
});


#2

THE RESULT IS Bad String
Status 200 ok


#3

Hi!

Replace this:

with this:

return $response->withJson($output);

#4

Expected ‘:’ instead of ‘’ :confused:


#5

This could be a malformed JSON. Please provide more details!


#6

Capture


#7

Capture


#8

Check your index.php file for invalid PHP tags.


#9

All other requets are working get post delete put just this


#10

Then try to validate your JSON string here: https://jsonlint.com/


#11

thanks for you :* :*