0

I am trying to get value with ajax and the values are in form of string, but the problem is when I'm trying to use a condition of if value empty then return this or else do that

My code is

if (empty($title) || empty($thumbnail) || empty($link))
{
    echo "404";
}
else
{
    some custom line
}

My problem is that a 404 is returned even if the value of any one of them (title, thumbnail, or link) is not empty. Can any one point me where I am wrong?

Here's how I am getting value from ajax:

$title = mysql_real_escape_string($_REQUEST['title']);
$thumbnail = mysql_real_escape_string($_REQUEST['thumbnail']);
$link = mysql_real_escape_string($_REQUEST['link']);
4

1 に答える 1

0

まず第一に、空を使用しないことをお勧めします。これは、特定の動作が発生するためです。

2 番目: mysql_real_escape_string を使用している理由がわかりません。データベースにクエリを実行する必要がありますか?

さらに、その値が設定されていない場合、(@havelock が指摘したように) 404 を取得したいと思います。

私はこれに賛成です:

if($title && $thumbnail && $link){
    //all fine..
}
else 404
于 2012-06-24T14:45:16.617 に答える