从url检索到的无法解释的符号

时间:2013-07-29 05:10:58

标签: php mysql facebook

我正在运行SQL查询以插入数据并向用户发送通知。

$query = "INSERT QUERY";    
$result = mysql_query($query);
$last_entry = mysql_insert_id();

通知代码。

$params = array("access_token"=>"MY_ACCESS_TOKEN","template"=>"Sample template","href"=>"index.php?id='$last_entry'");
$response = $facebook->api("/" . $reciever_id . "/notifications","POST",$params );

在索引页面中,我正在捕获id并使用以下代码回显它 -

if(isset($_GET['id']))
{
    $message_id = $_GET['id'];
    echo $message_id;
}

虽然一切正常,数据存储和通知功能都可以正常工作,但是在索引页面中,如果我的表中的id是35,我会将id作为\'35 \'。为什么要添加到开头和结尾的身份?

如果不可避免,是否有任何PHP功能可以帮助我消除它们?

1 个答案:

答案 0 :(得分:1)

single quotes移除$last_entry,例如

$params = array("access_token"=>"MY_ACCESS_TOKEN",
                "template"=>"Sample template",
                "href"=>"index.php?id=$last_entry");
$response = $facebook->api("/" . $reciever_id . "/notifications","POST",$params );

同时检查一下,您是否获得expected id中的$last_query

您可以在条件中查看numeric,例如

if(isset($_GET['id']) and is_numeric($_GET['id']))
{
    $message_id = $_GET['id'];
    echo $message_id;
}