2016-07-03 34 views
0

我有一個mysqli_query這樣的:PHP解析錯誤:語法錯誤

SELECT a.* FROM (SELECT `id` as `id`, `age` as `age` FROM `register` WHERE `age` !="") as a INNER JOIN (SELECT `one` as `f1` FROM `friends` WHERE `two`='".$my_id."' UNION SELECT `two` as `f2` FROM `friends` WHERE `one` = '".$my_id."') as b ON a.id=b.f1 

當我在SQL運行這個它沒有給出錯誤並顯示一個成功的查詢,但如果我在瀏覽器中運行它,我得到這個錯誤

(!) Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\wamp\www\functions.php on line 585

請任何人有一個想法,我怎麼能解決這個問題?

這是我的全部代碼

<?php 
    $con = mysqli_connect('localhost','root',''); 

    mysqli_select_db($con, 'qings'); 

    $my_id = '1'; 
    // the line below is my line 585 
    $query = mysqli_query($con, "SELECT a.* FROM (SELECT `id` as `id`, `age` as `age` FROM `register` WHERE `age` !="") as a INNER JOIN (SELECT `one` as `f1` FROM `friends` WHERE `two`='".$my_id."' UNION SELECT `two` as `f2` FROM `friends` WHERE `one` = '".$my_id."') as b ON a.id=b.f1"); 

?> 
+0

請提供一些代碼 – AkshayP

+0

顯示相關的PHP代碼,錯誤不在SQL查詢中 – LeleDumbo

+2

您需要發佈生成錯誤的PHP代碼。如錯誤消息所示,它位於第585行的'C:\ wamp \ www \ functions.php'中。 – mhawke

回答

1

變化,其中 '年齡'!= 「」WHERE '年齡'!=」 '

使用

$query = mysqli_query($con, "SELECT a.* FROM (SELECT `id` as `id`, `age` as `age` FROM `register` WHERE `age` !='') as a INNER JOIN (SELECT `one` as `f1` FROM `friends` WHERE `two`='".$my_id."' UNION SELECT `two` as `f2` FROM `friends` WHERE `one` = '".$my_id."') as b ON a.id=b.f1"); 
0

您應該只是逃避這裏的雙引號

​​