2011-11-19 68 views
-1

HTML:獲取登錄到正常工作

兩個HTML表單,看起來像: 當任買家或商家選擇img1

.. img2

 <form action="#" method="post"> 
       Buyer <input type="radio" name="addType" value="Buyer" /> 
       &nbsp;&nbsp;Merchant <input type="radio" name="addType" value="Merchant" /><br /> 
       New PricedWrite User? <a href="../register">Register</a> 
     </form> 
     <div class="buyer"> 
      <form method="post" action="check_buyer.php"> 
       Username or Email: <input class="UserReg" style="width:350px;" type="text" name="userName" /> <br /> 
       Password:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input class="UserReg" style="width:350px;" type="password" name="userPass" /> <br /> 
       <input type="submit" class="UserReg" name="submit" value="Sign In" /> 
      </form> 
     </div><!--/buyer--> 
     <br /> 
     <div class="merch"> 
      <form method="post" action="check_merchant.php"> 
       Username or Email: <input class="UserReg" style="width:350px;" type="text" name="userName" /> <br /> 
       Password: <input class="UserReg" style="width:350px;" type="password" name="userPass" /> <br /> 
       <input type="submit" class="UserReg" name="submit" value="Sign In" /> 
      </form> 

check_buyer.php(與html文件位於同一目錄)

<?php 
require_once('../inc/db/dbc.php'); 
$connect = mysql_connect($h, $u, $p) or die ("Can't Connect to Database."); 
mysql_select_db($db); 

$LoginUserName = $_POST['userName']; 
$LoginPassword = mysql_real_escape_string($_POST['userPass']); 
//connect to the database here 
$LoginUserName = mysql_real_escape_string($LoginUserName); 
$query = "SELECT uUPass, dynamSalt 
     FROM User 
     WHERE uUName = '$LoginUserName';"; 
$result = mysql_query($query); 
if(mysql_num_rows($result) < 1) //no such user exists 
{ 
    echo "No Such User"; 
} 
$ifUserExists = mysql_fetch_array($result, MYSQL_ASSOC); 

$dynamSalt = $ifUserExists['dynamSalt']; #get value of dynamSalt in query above 
$SaltyPass = hash('sha512',$dynamSalt.$LoginPassword); 


if($SaltyPass != $ifUserExists['uUPass']) //incorrect password 
{ 
    echo "No Such Pass<br />"; 
    echo '$LoginPass Value: '.$LoginPassword; 
} 

else 
{ 
echo "Success"; 
} 

?> 

目前,當我輸入一個有效的用戶並通過,它基本上只是重新加載頁面。這有什麼問題?

我最初創建時登記的通的方法是:

if(!empty($_POST['userPass'])) 
    $escapedInputtedPass=mysql_real_escape_string($_POST['userPass']); 
    $dynamSalt = mt_rand(); 
    $SaltyPass = hash('sha512',$dynamSalt.$escapedInputtedPass); 

爲什麼沒有這種匹配我檢查的方式嗎?唯一的區別是,它不必生成通行證,因爲通行證現在存儲在user tabledynamSalt列中。任何人都看到什麼$ SaltyPass = hash('sha512',$ dynamSalt。$ escapedInputtedPass);

+0

而不是重定向的(與'頭( '地點:的index.php')'行),返回錯誤信息(特定的錯誤信息),這樣你就會知道語句是否失敗,從而出現了什麼問題。如果沒有返回任何錯誤消息,那麼它甚至不會嘗試驗證登錄信息,這意味着您的表單設置不正確。 – Ben

+0

如果我這樣做,我會得到像這樣的錯誤消息:'最終沒有這樣的PassSuccess!' – meow

+0

請更新請... – meow

回答

-1

我天衣你在查詢有錯誤:

 
$query = "SELECT uUPass, dynamSalt 
     FROM User 
     WHERE uUName = '$LoginUserName';"; 

//change to 

$query = "SELECT uUPass, dynamSalt 
     FROM User 
     WHERE uUName = '$LoginUserName'"; //semicolon removed 

希望的作品

+0

爲什麼這應該有所作爲? –

+0

看到我想出來的方式。 – meow

+1

@AurelioDeRosa:你認爲,在sql查詢中使用這種方式的分號是好的......即使它沒有區別! –