Php MSQLI查询功能

时间:2015-11-13 20:42:28

标签: php

$username = $_POST['username'];
$password1 = $_POST['password1'];
$password2 = $_POST['password2'];
$email = $_POST['email'];
$keyId = $_POST['keyid'];
$verificationCode = $_POST['verificationcode'];
$accessMask = $_POST['accessmask'];
$connection = new mysqli('127.0.0.1', 'Web', 'pass', 'Account_Information');

if ($connection->connect_errno > 0) {
    die('Connection failed [' . $connection->connect_error . ']');
}

$usernameresults = $connection->query("SELECT `Username` FROM `Members_Information` WHERE 1 LIMIT 0, 30 ");

while ($row = $Usernameresults->fetch_assoc()) {
    if ($row['Username'] === $username) {
        echo "Username has already been choosen";
    }
    echo $row['Username'];
}

这是我当前的代码,它检索并回显正确的信息。我想做的是尽可能将while循环放入函数中? 代码执行的对象是验证用户名是否已存在于数据库中。我想将此作为一个函数或另一个选项,以便我接下来验证该电子邮件也不在数据库中。

我更愿意继续使用MSQLI。

1 个答案:

答案 0 :(得分:0)

我通常这样做

{{1}}