Search code examples
phpslim

Slim php framework 3 passing email in argument not working


I am having an error with slim PHP framework 3.

"The requested resource /try/[email protected]/secret was not found on this server."

I am new to slim PHP framework. When I enter email address "foo@bar" and password "secret" it yields a blank error (i.e. ""). When I enter email address "baz" and password "secret2" then it yields no error message.

I am basically making web service for Android, where the user will enter an email address and password and the required query will be returned in JSON format.

$app - > get('/try/{email}/{password}', function($request, $response, $args) {
    include_once('db.php');




    $email = $request - > getAttribute('email');
    echo $email;
    $password = $request - > getAttribute('password');
    echo $password;

    $sql = "select * from user where email='$email' and password='$password'";
    echo $sql;
    $result = mysqli_query($con, $sql);

    if (mysqli_num_rows($result) > 0) {
        // output data of each row
        $data[] = mysqli_fetch_assoc($result);
        header('Content-Type:application/json');
        echo json_encode($data);

    } else {
        echo "0 results";
    }

    mysqli_close($con);

});

Solution

  • @ is not a valid character inside an url: (see https://stackoverflow.com/a/1856809/1172363)

    You must create your link with urlencoded email value...

    $app->urlFor("your_route_name", array("email" => urlencode($mail), "password" => urlencode($password));
    

    In your case it would be (for example):

    http://yourserver/try/foo%40bar/your_pass