首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当激活状态时,警告框没有显示在正确的方向上。

当激活状态时,警告框没有显示在正确的方向上。
EN

Stack Overflow用户
提问于 2018-11-23 14:29:40
回答 1查看 54关注 0票数 0

我正在使用php注册。我只是让一切正常运转。将用户名填充的数据写入mySQUL数据。现在,我正在创造一个条件,即用户不能创建一个具有相同用户名的帐户。每个东西都正常工作,但是显示“用户名”的警告框没有像我想要的那样在login.php中显示,而是在registration.php中显示,并在我单击“确定”以关闭设置后返回。

首先,我尝试复制registration.php顶部的login.php代码,并将<form action="registration.php" method="post">更改为<form action="login.php" method="post">,该网站将不会像我所希望的那样工作。

我只想让警报框显示在login.php上,而不是在registration.php

这是代码

registration.php

代码语言:javascript
复制
<?php
session_start();
// header('location:login.php');
$con = mysqli_connect('localhost','root','');

mysqli_select_db($con, 'userregistration');

$name = $_POST['user'];
$pass = $_POST ['password'];
$email = $_POST['mail'];
$phone = $_POST['phone'];

$s = " SELECT * FROM usertable WHERE name = '$name'";

$result = mysqli_query($con, $s);

$num = mysqli_num_rows($result);

if (mysqli_num_rows($result) >= 1){
    $message="User already taken";
    echo "<script type='text/javascript'> alert('$message');
    window.location.replace(\"login.php\");
    </script>";
}else {
    $reg = "INSERT INTO usertable(name, password, email, phone ) values ('$name', '$pass','$email', '$phone')";
    mysqli_query($con, $reg);
    echo"Registration successfull";
}
?>

login.php

代码语言:javascript
复制
<html>
<head>
    <title> User Login</title>
    <link rel="stylesheet" type="text/css" href="mainbody.css">
    <link rel="stylesheet" type="text/css" href="loginheader.css">
    <link rel="stylesheet" type="text/css" href="signinsignup.css">
    <link rel="icon" href="../img/Polar_Bear-512.png">
</head>
<body>
<div class="loginheadercontain">
        <a href="../Index.php"><div class="dotcontain backtohomepage">
            <img src="047_-_homepage-512.png">
        </div></a>
        <div class="backtohomepage">
            <a href="../Index.php">Homepage</a>
        </div>
    </div>

</div>

<div class="login-wrap">
    <div class="login-html">
        <div class="containerlogin">
        <div class="avatarcontainer avatar">
            <img src="avatar.jpg">
        </div>
    </div>
        <div>
        <input id="tab-1" type="radio" name="tab" class="sign-in" checked>
        <label for="tab-1" class="tab">Sign In</label>
        <input id="tab-2" type="radio" name="tab" class="sign-up">
        <label for="tab-2" class="tab">Sign Up</label>
        <div class="login-form">
            <div class="sign-in-htm">
                <form action="validation.php" method="post">
                <div class="group">
                    <label for="user" class="label">Username</label>
                    <input id="user" type="text" name="user" class="input" placeholder="Enter Your Name" required>
                </div>
                <div class="group">
                    <label for="pass" class="label">Password</label>
                    <input id="pass" name="password" type="password" class="input" data-type="password" placeholder="Enter Your Password" required>
                </div>
                <div class="group">
                    <input type="submit" class="button" value="Sign In">
                </div>
                <div class="hr"></div>
                <div class="foot-lnk">
                    <label for="tab-2">Let's join our community!</a>
                </div>
                </form>
            </div>
        <div class="sign-up-htm">
            <form action="registration.php" method="post">
                <div class="group">
                    <label for="user" class="label">Username</label>
                    <input id="user" type="text" name="user" class="input" placeholder="Enter Your Name" required>
                </div>
                <div class="group">
                    <label for="user" class="label">Password</label>
                    <input id="pass" name="password" type="password" class="input" data-type="password" placeholder="Enter Your Password"required>
                </div>
                <div class="group">
                    <label for="user" class="label">Phone number</label>
                    <input type="tel" name="phone" class="input"placeholder="Enter Your Phone Number">
                </div>
                <div class="group">
                    <label for="user" class="label">Email</label>
                    <input type="email" name="mail" class="input" placeholder="Enter Your Email">
                </div>
                <div class="group">
                    <input type="submit" class="button" value="Sign Up">
                </div>
                <div class="hr"></div>
                <div class="foot-lnk">
                    <label for="tab-1">Already Member?</a>
                </div>
            </form>
        </div>
        </div>    
    </div>
</body>
</html>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-23 15:02:15

注册表单的操作值应该是相同的login.php文件,其中还应该移动有关注册用户的逻辑。

或者您可以在registration.php中移动html (对于GET请求),以及当您的请求被发布以运行您的php代码时。

代码语言:javascript
复制
if (isset($_POST)) {
    // run php code from registration.php
} else  {
    ?>
    HTML CODE with your registration form
    <?php
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53448528

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档