2013-03-14 194 views
0

我創建其鏈接到數據庫的登錄,輸入信息時登錄然後運行一個空白頁,什麼也不做,下面是我的代碼:PHP登錄問題

include "conn.php"; 
    session_start(); 

    $email_address = $_POST['email_address']; 
    $password = $_POST['password']; 

    if ($email_address && $password) 
    { 
    $connect = mysql_connect("computing","i7906890","password") or die ("couldn't connect!"); 
    mysql_select_db("i7906890") or die ("couldn't find database"); 
$guery = mysql_query("SELECT * FROM UserAccount WHERE email_address = '$email_address'"); 

if ($numrows!=0) { 
    //code to login 
    while ($row = mysql_fetch_assoc($query)) //Password Check 
    { 
     $dbemail_address = $row['email_address'] 
     $dbpassword = $row['password'] 
    } 
    //Check if they match 
    if ($email_address==$dbemail_address&&$password==$dbpassword) 
    { 
     echo "You're in! <a href='user_page.php'>click</a> here to enter the members page"; 
     $_SESSION['user']==$dbemail_address; 
    } 
    else 
     echo "Incorrect Password!"; 
} 
else 
    die("That user doesn't exist!"); 
} 
else 
    die("Please enter an email address and password!"); 
?> 

而且,這裏是我的形式

<form action = "login2.php" method ="POST"> 
     <p><img src="images/space.gif" width="70px" height="1px"/><strong>Log in</strong> or <a href="register_form.php"><strong>Register</strong></a><br> 
      Email:<img src="images/space.gif" width="34px" height="1px"/><input type="text" name="user" size="33"> <br> 
      Password:<img src="images/space.gif" width="10px" height="1px"/><input type="password" name="password" size="33"> <br> 
     <div align="center"> 
     <input type="submit" value="Log in" class="button"> 
     </div> 
    </p> 
    </form> 

請幫忙! SOS

+0

什麼是最小代碼工作?你必須看看哪裏出了問題,診斷究竟是什麼原因,然後研究修復/避免這種情況。那麼,如果你失敗了,你可以問一個問題,「不工作」不是一個問題。 – 2013-03-14 13:38:45

+1

'請幫忙! SOS'是的,你的意思很深......但並不符合你的期望......即使你的代碼運行良好,你也是第5或第6位,他們大致提出了同樣的問題,充滿了[SQL注入](http://en.wikipedia.org/wiki/SQL_injection)在PHP登錄表單中使用已棄用的** mysql _ **函數... – ppeterka 2013-03-14 13:39:27

+0

做一些調試。 '回聲「在這裏達到等等等等;'在每個塊和條件之後檢查執行哪個路徑。你也可以輸出變量,所以你會知道究竟是什麼被髮送到頁面,從數據庫中獲取什麼,等等...... – 2013-03-14 13:42:18

回答

2

你錯過了幾個;在你的代碼,這是導致腳本廢話,不顯示任何東西。 (具體表現在while循環,但檢查其他地方也是如此。)

編輯:您可能還需要考慮丟失該while環路一起,把密碼標準的SQL語句中有更好的表現。和其他海報一樣,注意SQL注入。

+0

好的,謝謝我將修復這些 – 2013-03-14 13:41:25

0

Please help! SOS是的,你在深SH ......但不是你所期望...

即使你的代碼運行良好,你是誰,問大致相同的第五或第六問題,使用過時的mysql_功能在PHP登錄表單與SQL injection千瘡百孔......

而且也$guery是不一樣的$query ...檢查爲q的d 信...

這條線:

$guery = mysql_query("SELECT * FROM UserAccount WHERE email_address = '$email_address'"); 

應至少

$query = mysql_query("SELECT * FROM UserAccount WHERE email_address = '".mysql_real_escape($email_address)."'"); 

雙方是正確的,並避免注射...

但你應真的使用通過PDO準備好的聲明,如下所示:

try { 
    //open connection, this is different than in the old functions 
    $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass); 

    //***running query 
    //**step1: create statement 
    $stmt = $dbh->prepare('SELECT * FROM UserAccount WHERE email_address = :email'); //notice parameter prefixed with ':' 

    //**step2: bind values (be sure to also check out the bindParameter() function too!) 
    $stmt->bindValue(':email', $email_address); 

    //**step3: exexcute statement 
    $stmt->execute(); 

    //**step4: process results 
    $result = $stmt->fetch(PDO::FETCH_OBJ); 

    if($result->PASSWORD==$password) { 
     //logged in, do whatever reuqired 
    } 

    $dbh = null; //don't let it slip out of our hands 
} catch (PDOException $e) { 
    print "Error!: " . $e->getMessage() . "<br/>"; 
    die(); 
} 

另外,謹慎的另一個詞:不要存儲明文密碼。即使存儲MD5哈希值現在已超出範圍,並且SHA1也被聲明爲弱...

+0

por錯誤..感謝你發現它 – 2013-03-14 13:44:57

+0

打算把sha1放在後面,只想讓基本登錄工作第一個 – 2013-03-14 13:57:19

+0

也許「聲稱是弱」而不是「有爭議的是弱「? – 2013-03-14 14:32:54