猿问

如何从我的数据库中获取注册消息

我正在设置完全有组织的注册表单,我正在尝试将信息发送到我的 MySQL 数据库服务器中。我的代码不起作用,无法弄清楚弹出消息您已注册!

我尝试了几个选项,但没有一个在服务器上工作,


<?php

if (array_key_exists('email', $_POST) or array_key_exists('password', $_POST)) {

    // So I'm guessing here need to some additions of based my own inclinatios.

我的代码


<?php

    if (array_key_exists('email', $_POST) or array_key_exists('password', $_POST)) {

        $link = mysqli_connect("localhost", "id8955440_bigebro", "sunshine1987**", "id8955440_bigebro");

        if (mysqli_connect_error()) {

            die("There was an error connecting to the database");

        }

        if ($_POST['email'] == '') {

            echo "<p>Email address is required.</p>";

        } else if ($_POST['password'] == '') {

            echo "<p>Password is required.</p>";

        } else {

            $query = "SELECT `id` FROM `bigebro` WHERE email = '" . mysqli_real_escape_string($link, $_POST['email']) . "'";

            $result = mysqli_query($link, $query);

            if (mysqli_num_rows($result) > 0) {

                echo "<p>That email address has already been taken.</p>";

            } else {

                $query = "INSERT INTO `bigebro` (`email`, `password`) VALUES ('" . mysqli_real_escape_string($link, $_POST['email']) . "', '" . mysqli_real_escape_string($link, $_POST['password']) . "')";

                if (mysqli_query($link, $query)) {

                    echo "<p>You have been signed up!";

                } else {

                    echo "<p>There was a problem signing you up - please try again later.</p>";

                }

            }

    }

}

?>

HTML


<form method="post">

    <input name="email" type="text" placeholder="Email address">

    <input name="password" type="password" placeholder="Password">

    <input type="submit" value="Sign up">

</form>

$link = mysqli_connect("localhost", "id8955440_bigebro", "sunshine1987**", "id8955440_bigebro");


当我注册表格时只弹出“注册您时出现问题 - 请稍后再试”我希望从结果中得到“您已注册”。请看报名表


largeQ
浏览 138回答 2
2回答

翻翻过去那场雪

使用mysqli_error查询跟踪误差。$query = "INSERT INTO `bigebro` (`email`, `password`) VALUES ('" . mysqli_real_escape_string($link, $_POST['email']) . "', '" . mysqli_real_escape_string($link, $_POST['password']) . "')";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mysqli_query($link, $query)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "<p>You have been signed up!";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "Error: " . mysqli_error($conn);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }还要检查你的数据库结构,比如 id 应该自动递增,电子邮件和密码应该是 varchar。
随时随地看视频慕课网APP
我要回答