2016-09-29 98 views
-7

我有我在郵遞員正在執行我的PHP腳本錯誤在Android的studio.the響應部分使用不執行它給了一個錯誤
PHP登錄腳本JSON錯誤

<b>Parse error</b>: syntax error, unexpected '$response' (T_VARIABLE) in 
<b>/home/u259428939/public_html/Login.php</b> on line 
<b>23</b> 
<br /> 

請幫我出。

<?php 
    $con = mysqli_connect("", "", "", ""); 

    $username = $_POST["username"]; 
    $password = $_POST["password"]; 


    $query = "SELECT * FROM user_info WHERE username = '$username' AND password ='$password'"; 
    $result=mysqli_query($con,$query); 

    $response=array(); 


    if(mysqli_num_rows($result)>=1) 
    { 
     $data=mysqli_stmt_fetch($result) 
     $response['success'] = 'true'; 
     $response["name"] = $data['name']; 
     $response["age"] = $data['age']; 
     $response["username"] = $data['username']; 
     $response["password"] = $data['password']; 

    } 

    if(mysqli_num_rows($result)<1){ 
     $response["success"] = 'false'; 

    } 
    echo json_encode($response); 
?> 
+1

我們不會爲你做你的功課。 23號線在哪裏,你試圖解決什麼問題等。 –

+0

YIKES!您正在使用純文本密碼! PHP提供['password_hash()'](http://php.net/manual/en/function.password-hash.php) 和['password_verify()'](http://php.net/manual/ en/function.password-verify.php)請使用它們。 這裏有一些[有關密碼的好點子(https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet) 如果您使用的是PHP版本5.5之前的[有可以在這裏找到一個兼容包(HTTPS :在這個線//github.com/ircmaxell/password_compat) – RiggsFolly

+0

$數據= mysqli_stmt_fetch($結果)忘記把 「;」。它應該$ data = mysqli_stmt_fetch($ result); –

回答

0

你缺乏一個分號(;)在該行的末尾:

$data=mysqli_stmt_fetch($result) 
           ^
1

你犯了小錯誤串聯PHP變量與在SQL查詢字符串。請修正下面的腳蹼。

<?php 
    $con = mysqli_connect("", "", "", ""); 

    $username = $_POST["username"]; 
    $password = $_POST["password"]; 


    $query = "SELECT * FROM user_info WHERE username = '".$username."' AND password ='".$password."'"; 
    $result=mysqli_query($con,$query); 

    $response=array(); 


    if(mysqli_num_rows($result)>=1) 
    { 
     $data=mysqli_stmt_fetch($result); 
     $response['success'] = 'true'; 
     $response["name"] = $data['name']; 
     $response["age"] = $data['age']; 
     $response["username"] = $data['username']; 
     $response["password"] = $data['password']; 

    } 

    if(mysqli_num_rows($result)<1){ 
     $response["success"] = 'false'; 

    } 
    echo json_encode($response); 
?> 
0

沒有以data命名的數組。所以$data['name']不可用。

if(mysqli_num_rows($result)>=1) 
{ 
    $data=mysqli_stmt_fetch($result);//semi colon was missing 
    $response['success'] = 'true'; 
    $response["name"] = $data['name'];//unable to find $data array 
    $response["age"] = $data['age'];//unable to find $data array 
    $response["username"] = $data['username'];//unable to find $data array 
    $response["password"] = $data['password'];//unable to find $data array 

}