2013-02-11 115 views
-1

我11歲,我正在爲我和我的朋友建立一個聊天網站。我使用MYSQLi來處理數據庫的事情,而且我還挺新的。我一直使用普通的mysql。如何檢查電子郵件是否存在MYSQLi

哦!如果你可以分享一個鏈接到一個mysqli的教程,這將是巨大的:)

那麼這裏是我的配置文件

<?PHP      


define("HOST", "localhost"); define("USER", "root"); define("PASSWORD", "****"); define("DATABASE", "secure_login"); 

$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE); 

?> 

的數據庫secure_login,然後我有一個表稱爲成員,然後該表中名爲電子郵件的列。

我把這個包含在一個文件(register.php)中,我必須檢查郵件是否存在。如果存在,重定向到家。

如果你們可以幫助我,這將是很酷!我希望儘快完成:)

+0

不要使用mysqli的,使用PDO來代替 – 2013-02-12 10:47:37

回答

1

我會從MySQLi文檔http://php.net/manual/en/book.mysqli.php開始閱讀,具體涉及該類的方法。如果您需要教程,我建議您在Google上進行搜索,網上有大量教程。

至於你的問題,這樣的事情應該工作:

$query = "SELECT email FROM members WHERE USER = ? AND PASS = ?"; 

if ($stmt = $mysqli->prepare($query)){ 
     // Bind the parameters, these are the ?'s in the query. 
     $stmt->bind_param("ss", $username, sha1($password)); 
     // Execute the statement 
     if($stmt->execute()){ 
      // get the results from the executed query 
      $stmt->store_result(); 

      $email_res= "";   
      // This stores the value of the emailaddres inside $email_res 
      $stmt->bind_result($email_res); 


      $stmt->fetch(); 

      // There is a result 
      if ($stmt->num_rows == 1){ 

          // Validate the emailadres here, check the PHP function filter_var() 

      } 
      else { 
        // Not a valid email 
      } 
     } 
     else { 
      printf("Execute error: %s", $stmt->error); 
     } 

    } 
    else { 
     printf("Prepared Statement Error: %s\n", $mysqli->error); 
    } 
} 

我希望這有助於

相關問題