2017-02-10 59 views
0

描述info--登錄校驗碼在PHP

enter image description here

<?php 

$loginpassword = $_POST['password']; 
$loginemail = $_POST['email']; 

//connect 
    $my_hostname = "localhost"; 
    $my_user = "root"; 
    $my_password = "root"; 

    $connect = mysql_connect($my_hostname, $my_user, $my_password); 

    $mysql_database = "myapp"; 
    mysql_select_db($mysql_database, $connect); 

//email and password check 
    $query = "SELECT * FROM hw2 WHERE email = '$loginemail'"; 
    $check= mysql_query($query); 
    $result = mysql_num_rows($check); 

    if ($result = 0) { 
    die("EmailID does not exist"); 
    } 




// part 3 
if ($loginemail = "[email protected]" and $loginpassword = "12345") { 
    $sql_sel_query = "SELECT * FROM hw2"; 
    $result = mysql_query($sql_sel_query); 
    $total_num_rows = mysql_num_rows($result); 
    $i=0; 
    while ($i < $total_num_rows) { 
    $new_row = mysql_fetch_array($result); 
    $firstname_dis = $new_row['firstname']; 
    $lastname_dis = $new_row['lastname']; 
    echo "$firstname_dis"; 
    echo "--"; 
    echo "$lastname_dis"; 
    echo "<BR>"; 

    $i=$i+1; 
} 



?> 

我新的PHP代碼,在這裏我想實現的功能中附加的想象。但我有點在步驟b中迷失了。任何人都可以幫助我,並在可能的情況下檢查其他步驟是否正確。

+0

對不起你們,請點擊 「在這裏輸入圖像描述」看到附件的想象。 –

+1

使用mysql_ *函數停止!他們不安全,不推薦,不見了。改用mysqli_ *或PDO。 – Jeff

+0

如果電子郵件地址錯誤或電子郵件地址正確但密碼錯誤,我不建議給出具體的答覆。這使得更容易入侵。相反有一個答覆「憑據是錯誤的」 – Jeff

回答

1

您應該使用雙等號。

if ($result == 0) { 

,而不是

if ($result = 0) { 

而且,改變這一行:

if ($loginemail = "[email protected].com" and $loginpassword = "12345") { 

這樣:

if ($loginemail == "[email protected]" and $loginpassword == "12345") { 
+1

也許還加'$ loginemail ='和密碼 – Jeff

+0

謝謝。我編輯它。 – Thanasis