2013-02-11 3 views
-1

저는 11 세이고 저와 친구들을 위해 채팅 사이트를 만들고 있습니다. 나는 데이터베이스 것들을 다루기 위해 MYSQLi를 사용하고 있으며, 나는 그것에 대해 약간 새로운 것이다. 나는 항상 보통의 mysql을 사용했다.MYSQLi에 이메일이 있는지 확인하는 방법

오! 당신이 mysqli 튜토리얼에 대한 링크를 공유 할 수 있다면, 그것은 것 큰 :)

는 자, 여기 한 후 내 구성 데이터베이스는 secure_login됩니다

<?PHP      


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

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

?> 

, 그때 나는 테이블이 멤버를 불렀다

파일과의 그 테이블에있는 email이라는 이름의 컬럼.

전자 메일의 존재 여부를 확인해야하는 파일 (register.php)에이 내용이 포함되어 있습니다. 그리고 그것이 존재한다면, 집으로 리디렉션하십시오.

너희들이 나를 도와 준다면 멋질거야 !!! 곧 마무리하겠습니다.

+0

가 mysqli를 사용하지 마십시오 도움이되기를 바랍니다 대신 PDO를 사용 –

답변

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); 
    } 
} 

을 나는,이

관련 문제