函数中的if语句中的t字符串错误

时间:2012-05-04 18:31:25

标签: php mysql

我一直收到这个错误:

PHP解析错误:语法错误,意外T_STRING

对于这一行:

if($email_addr == "") /* If real email not found, return FALSE*/

我无法弄清楚出了什么问题,并尝试了很多东西,研究了两天而没有修正。我想知道是否有其他人可以看到我做错了什么。为什么我收到此错误?谢谢。 (功能如下)

    function searchRecipient() // function to search the database for the real email
{
    global $MessageSentToMailbox; // bring in the alias email
    $email_addr = mysql_query("SELECT email FROM tbl WHERE source='$MessageSentToMailbox'"); // temp store of the real email
    $row = mysql_fetch_assoc($email_addr); //making temp store of data for use in program
    if($email_addr == "") /* If real email not found, return FALSE*/
    {
        return FALSE;
    }
    else  /* Else, return find the person's name and return both in an array */
    {
        $query = "SELECT * FROM tbl WHERE email = '$email_addr'"; // pulling in the row where the emails match
        $results = mysql_query($query, $email_addr); // temp store of both queries from this function
        $row = mysql_fetch_assoc($results); //making temp store of data for use in program
        $name = $row['author'];  // taking the author data and naming its variable
        return array($name, $email_addr);  // this is the name and the real email address to be used in function call
    }
}

2 个答案:

答案 0 :(得分:1)

您正在将资源与字符串进行比较。

你真正想做的是:

if ($row['email']== "")

或者,甚至更好:

if (empty($row['email']))

答案 1 :(得分:0)

if($row['email']== "") /* If real email not found, return FALSE*/
    {
        return FALSE;
    }