2014-02-08 100 views
0

我是以下查詢來驗證表單發佈的登錄信息。但是,每當我運行查詢我得到內部服務器錯誤。我不確定我做錯了什麼。使用php執行查詢

<?php 
if(isset($_POST["userName"]) && isset($_POST["password"])){ 
$userName = $_POST["userName"]; 
$password = $_POST["password"]; 
include "http://evocature.com/scripts/db_connect.php"; 
$results = mysql_query("SELECT id 
         FROM admins 
         WHERE userName = '$userName' 
         AND password ='$password' LIMIT 1"); 

$existCount = mysql_num_rows($results); 
if($existCount == 1){ 
    while($row = mysql_fetch_array($results)){ 
     $id = $row["id"]; 
    } 
    $_SESSION["id"] = $id; 
    $_SESSION["manager"] = $manager; 
    $_SESSION["password"] = $password; 
    header("Location: http://www.evocature.com/admin/index.php"); 
    exit(); 
} 
else{ 
    echo 'Invalid Information'; 
    exit(); 
} 

} 
+0

什麼是錯誤? –

+0

我得到500內部服務器錯誤 –

+2

[請不要在新代碼中使用'mysql_ *'函數](http://bit.ly/phpmsql)。他們不再被維護[並被正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到[紅框](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 **您也可以[SQL注入](http://stackoverflow.com/q/60174)** –

回答

0

我相信你不能包括http頁面。那麼不用這種方法。

+0

我將它改爲../scripts/db_connect.php,並沒有什麼區別。 –

+0

檢查是否在db_connect.php中出現錯誤。無論如何,如前所述,我建議使用PDO類http://www.php.net/manual/en/book.pdo.php –