简体   繁体   English

PHP-网址上具有两个或多个参数的GET方法

[英]PHP - GET method with two or more parameters on the url

I'm using Slim framework to create a REST API . 我正在使用Slim framework来创建REST API I'm trying to use two parameters in the url of the method but it gives to me a 404 Page Not Found error. 我正在尝试在方法的网址中使用两个参数,但它给我一个404 Page Not Found错误。

Here it's my code: 这是我的代码:

$app->get("/getUser/:user/:password",function($user,$password) use($app)
{
    try{
        $connection = getConnection();
        $dbh = $connection->prepare("SELECT idUser FROM users WHERE user = ? and password = ?");
        $dbh->bindParam(1,$user);
        $dbh->bindParam(2,$password);
        $dbh->execute();
        $user = $dbh->fetchObject();
        $connection = null;

        header("HTTP/1.1 200");
        header("Content-Type:application/json; charset=utf-8");

        echo json_encode($user,JSON_UNESCAPED_UNICODE );

    }catch(PDOException $e)
    {
        echo "Error: " . $e->getMessage();
    }
});

If I make the method with just one parameter it works but in the same moment I put two methods it doesn't found anything. 如果我仅使用一个参数来创建该方法,则该方法有效,但同时放置两个方法,则一无所获。

Is it possible to send two parameters in the url? 是否可以在网址中发送两个参数? How can I do that? 我怎样才能做到这一点?

Thanks in advance! 提前致谢!

1) It is possible to send 2 params in Slim . 1)可以在Slim发送2个参数。 2) Are you sure the value in password param is matching with any of the values in that field? 2)您确定密码参数中的值与该字段中的任何值匹配吗?

Finally I got the solution to my problem. 终于我找到了解决问题的办法。 The problem was on the query. 问题出在查询上。 I translated the code to English (the parts that weren't on English before, like variables, etc) for a better comprehesion about my problem. 我将代码翻译成英语(以前没有用英语的部分,例如变量等)来更好地理解我的问题。

The problem was there, because the name of the variable password got a character that I think MySQL doesn't support and it's when I got the error. 问题就在那里,因为变量password的名称有一个我认为MySQL不支持的字符,而这正是我得到错误的时间。 Now I changed the name of my variable to password and it works properly! 现在,我将变量名更改为password ,它可以正常工作!

I put as an answer because maybe someone has the same problem as me. 我回答,因为也许有人和我有同样的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM