-1

我今年 11 岁,正在为我和我的朋友创建一个聊天网站。我正在使用 MYSQLi 来处理数据库的事情,而且我对它有点陌生。我一直使用普通的mysql。

哦!如果你能分享一个mysqli教程的链接,那就太好了:)

好吧,这是我的配置文件

   <?PHP                     


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

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

?>

数据库是secure_login,然后我有一个名为 members 的表,然后在该表中有一个名为 email 的列。

我将它包含在一个文件(register.php)中,我必须在其中检查电子邮件是否存在。如果它存在,重定向到家。

如果你们能帮助我,那就太好了!!!我希望尽快完成这个:)

4

1 回答 1

0

我将从阅读http://php.net/manual/en/book.mysqli.phpMySQLi上的文档开始,特别是与类相关的方法。如果您需要教程,我建议您在 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);
    }
}

我希望这有帮助

于 2013-02-12T10:41:37.430 回答