php寫了個登陸,伺服器報錯500.

來源:互聯網
上載者:User
代碼如下:
表結構

id         int phone      charpassword   char

Conn.php

錯誤原因:'.mysql_error());    //設定字元集,如utf8和gbk等    mysql_query("set names 'utf8'");    //選定資料庫    mysql_select_db($db_name,$conn) or die('資料庫選定失敗!
錯誤原因:'.mysql_error()); //執行SQL語句(查詢) //$result = mysql_query($sql) or die('資料庫查詢失敗!
錯誤原因:'.mysql_error());?>

login.php

'非法請求'));            return false;        }                //建立SQL語句        $sql="SELECT * FROM lms_users WHERE phone ='".$userName."' AND `password` = '".$userPassword."';";            //調用conn.php檔案進行資料庫操作        require('Conn.php');        global $conn;                $result=mysql_query($sql,$conn) or die('資料庫查詢失敗!錯誤原因:'.mysql_error());                $flag=0;        while(!!$item=mysql_fetch_assoc($result)){            $flag++;        };        //實際只能返回一條結果.        if ($flag >= 1) {            $result = array(                            echo json_encode($row);                           );            echo json_encode($result);            exit();        }else {            $result = array(                            'id' => 0                            );            echo json_encode($result);        }        return true;?>

login.html

        PHP 測試    

登陸

回複內容:

代碼如下:
表結構

id         int phone      charpassword   char

Conn.php

錯誤原因:'.mysql_error());    //設定字元集,如utf8和gbk等    mysql_query("set names 'utf8'");    //選定資料庫    mysql_select_db($db_name,$conn) or die('資料庫選定失敗!
錯誤原因:'.mysql_error()); //執行SQL語句(查詢) //$result = mysql_query($sql) or die('資料庫查詢失敗!
錯誤原因:'.mysql_error());?>

login.php

'非法請求'));            return false;        }                //建立SQL語句        $sql="SELECT * FROM lms_users WHERE phone ='".$userName."' AND `password` = '".$userPassword."';";            //調用conn.php檔案進行資料庫操作        require('Conn.php');        global $conn;                $result=mysql_query($sql,$conn) or die('資料庫查詢失敗!錯誤原因:'.mysql_error());                $flag=0;        while(!!$item=mysql_fetch_assoc($result)){            $flag++;        };        //實際只能返回一條結果.        if ($flag >= 1) {            $result = array(                            echo json_encode($row);                           );            echo json_encode($result);            exit();        }else {            $result = array(                            'id' => 0                            );            echo json_encode($result);        }        return true;?>

login.html

        PHP 測試    

登陸

開發的話要開啟php的錯誤顯示(在php.ini中搜尋配置display_errors=On),才能知道具體是啥錯誤。

另外,建議不要使用mysql相關函數了,用mysqli相關函數或對象代替,mysql相關函數早就不推薦使用,並在最新的PHP7中正式移除了。

有語法錯誤吧,

$result = array(    echo json_encode($row););                       

這裡是錯誤的。其實可以開啟伺服器上詳細錯誤的輸出,這樣可以看到500錯誤具體的出錯原因

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.