2017-05-15 75 views
-1

我的問題是,條件if(isset ... is not seeable。直到現在我沒有與PDO一起工作,所以如果有人看到我的問題的解決方案,請幫助我,如果可以的話,謝謝激活郵件和散列檢查

<?php 

     mysql_connect("localhost", "xxxx", "") or die(mysql_error()); // Connect to database server(localhost) with username and password. 
     mysql_select_db("database") or die(mysql_error()); // Select registration database. 

這種情況如果不能看到

if (isset($_GET['e_mail']) && !empty($_GET['e_mail']) AND isset($_GET['hash']) && !empty($_GET['hash'])){ 
      // Verify data 
      $email = mysql_escape_string($_GET['e_mail']); // Set email variable 
      $hash = mysql_escape_string($_GET['hash']); // Set hash variable 

      $search = mysql_query("SELECT e_mail, hash, active FROM users WHERE e_mail='".$email."' AND hash='".$hash."' AND active='0'") or die(mysql_error()); 
      $match = mysql_num_rows($search); 

我想這樣做的條件:

  if($match > 0){ 
       // We have a match, activate the account 
       mysql_query("UPDATE users SET active='1' WHERE e_mail='".$email."' AND hash='".$hash."' AND active='0'") or die(mysql_error()); 
       echo '<div class="statusmsg">Your account has been activated, you can now login</div>'; 
      }else{ 
       // No match -> invalid url or account has already been activated. 
       echo '<div class="statusmsg">The url is either invalid or you already have activated your account.</div>'; 
      } 


     } 

如果條件做到這一點:

else{ 


       // Invalid approach 
       echo '<div class="statusmsg">Invalid approach, please use the link that has been send to your email.</div>'; 

      } 
      ?> 
+1

***請[停止使用'mysql_ *'功能](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。*** [這些擴展名](http://php.net/manual/en/migration70.removed-exts-sapis.php)已在PHP 7中刪除。瞭解[prepared](http://en.wikipedia.org/wiki/Prepared_statement)語句[PDO](http://php.net/manual/en/pdo.prepared-statements.php)和[MySQLi](http://php.net/manual/en/mysqli.quickstart。 prepared-statements.php)並考慮使用PDO,[這真的很簡單](http://jayblanchard.net/demystifying_php_pdo.html)。 –

+1

[小博](http://bobby-tables.com/)說***腳本是在對SQL注入攻擊的風險。(http://stackoverflow.com/questions/60174/how-can- I-防止-SQL注入式-PHP)***。即使[轉義字符串](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)是不安全的! –

+0

你的代碼失敗了;檢查錯誤 –

回答

0

我發現那裏的錯誤是, 這聽起來令人難以置信,但錯就錯在哪兒了底線(_)設置數據庫,當我在數據庫中,並正確輸入所有電子郵件代替的e_mail,它完美的作品。

我上傳的答案,因此它可以幫助其他有同樣的情況。

我非常欣賞周杰倫Blanchard's建議在PDO工作,我會送他的A設備,因爲它是有說服力的,感謝你弗雷德的回答。

現在,如果有人可以幫我做(寫,做)這個代碼在PDO和解釋我PDO是如何工作的,以便更好地理解它。謝謝!