在一个文件数据中包含2个php文件,彼此重叠

时间:2017-02-04 00:29:10

标签: php html database insert include

我必须在一个表中注册表单,目标是1个模式,每个包含在另一个页面中的php,并且它有几乎相似的字段,clientignup还有2个,但每当我尝试在下面包含它们时,clientsignup重叠surveyesignup的插入代码,而如果我只包括一个它完美的工作。我已经尝试将它们从一个文件夹中分离出来。

<body id="page-top">

    <nav id="mainNav" class="navbar navbar-default navbar-fixed-top">
        <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span> Menu <i class="fa fa-bars"></i>
                </button>
                <a class="navbar-brand page-scroll" href="#page-top">Home</a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <div class="dropdown">
                            <a href="#" class="btn btn-simple dropdown-toggle" data-toggle="dropdown" style="line-height:2.828571;"><font color="#d3d3d3">Sign Up</font><b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li><a href="#surveyeesignup" data-target="#surveyeesignup"  data-toggle="modal">As User</a></li>
                                <li><a href="#clientsignup" data-target="#clientsignup" data-toggle="modal">As Client</a></li>
                            </ul>
                        </div>
                    </li>
                    <li>
                        <a href="#">Login</a>
                    </li>
                    <li>
                        <a class="page-scroll" href="#services">Services</a>
                    </li>
                    <li>
                        <a class="page-scroll" href="#portfolio">Portfolio</a>
                    </li>
                    <li>
                        <a class="page-scroll" href="#contact">Contact</a>
                    </li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container-fluid -->
    </nav>

    <div id class="container">

        <?php include("./formstwo/ClientSignup.php"); ?>
        <?php include("./forms/SurveyeeSignup.php"); ?>

    </div>

客户注册

<?php
if(isset($_POST['submit'])){

    include("./forms/connection.php");
    $username = $_POST['username'];
    $fullname = $_POST['fullname'];
    $email = $_POST['email'];
    $companyname = $_POST['companyname'];
    $website = $_POST['website'];
    $password = $_POST['password'];
    $confirmpassword = $_POST['confirmpassword'];

    $user = mysqli_query($con, "SELECT username from user WHERE username = '".$username."'");
    $count = mysqli_num_rows($user);

    if($password != $confirmpassword){
        echo '<script language="javascript">';
        echo 'alert("Password does not match!")';
        echo '</script>';
    }
    else{
        if($count != 0){
            echo '<script language="javascript">';
            echo 'alert("Username already exists!")';
            echo '</script>';
        }

        else{

            $insert = mysqli_query($con, "INSERT INTO `user` (`username`,`fullname`,`email`,`companyname`,`website`,`age`,`password`,`gender`,`occupation`,`usertype`) VALUES ('$username','$fullname','$email','$companyname','$website','','$password','','','Client')");
            if(!$insert){
                echo mysqli_errno();
            }
            else{
                echo '<script language="javascript">';
                echo 'alert("Registration Success!")';
                echo '</script>';
            }
        }
    }
}
?>


<div id="clientsignup" class="modal" tabindex="1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" id="close" class="close" data-dismiss="modal">&times;</button>
                <h3 class="modal-title">Sign Up</h3>
            </div>

            <div class="modal-body">
                <div class="row">

                    <form action="#" method="POST">

                        <div class="row form-group">
                            <div class="col-sm-12">
                                <input type="text" name="username"  id="username" class="form-control" placeholder="Username">
                            </div>
                        </div>

                        <div class="row form-group">
                            <div class="col-sm-12">
                                <input type="text" name="fullname"  id="fullname" class="form-control" placeholder="Fullname">
                            </div>
                        </div>

                        <div class="row form-group">
                            <div class="col-sm-12">
                                <input type="email" name="email" id="email" class="form-control" placeholder="Email">
                            </div>
                        </div>

                        <div class="row form-group">
                            <div class="col-sm-12">
                                <input type="text" name="companyname" id="companyname" class="form-control" placeholder="Company Name">
                            </div>
                        </div>

                        <div class="row form-group">
                            <div class="col-sm-12">
                                <input type="text" name="website" id="website" class="form-control" placeholder="Website (OPTIONAL)">
                        </div>
                        </div>

                        <div class="row form-group">
                            <div class="col-sm-12">
                                <input type="password" name="password" id="password" class="form-control" placeholder="Password">
                            </div>
                        </div>

                        <div class="row form-group">
                            <div class="col-sm-12">
                                <input type="password" name="confirmpassword" id="confirmpassword" class="form-control" placeholder="Confirm Password">
                            </div>
                        </div>

                        <div class="row form-group">
                            <div class="col-sm-12">
                                <input type="submit" name="submit" id="sign_up" class="form-control btn btn-primary" value="Sign Up">
                            </div>
                        </div>





                    </form>

                </div>

            </div>

            <div class="modal-footer">
                <p class="text-center">Already have an account? <a href="">Login</a></p>


            </div>

        </div>

    </div>

</div>

Surveyee注册

<?php
if(isset($_POST['submit'])){

   include("connection.php");
    $username = $_POST['username'];
    $fullname = $_POST['fullname'];
    $email = $_POST['email'];
    $age = $_POST['age'];
    $password = $_POST['password'];
    $confirmpassword = $_POST['confirmpassword'];
    $gender = $_POST['gender'];
    $occupation = $_POST['occupation'];

    $user = mysqli_query($con, "SELECT username from user WHERE username = '".$username."'");
    $count = mysqli_num_rows($user);

    if($password != $confirmpassword){
        echo '<script language="javascript">';
        echo 'alert("Password does not match!")';
        echo '</script>';
    }
    else{
        if($count != 0){
            echo '<script language="javascript">';
            echo 'alert("Username already exists!")';
            echo '</script>';
        }

        else{

            $insert = mysqli_query($con, "INSERT INTO `user` (`username`,`fullname`,`email`,`companyname`,`age`,`password`,`gender`,`occupation`,`usertype`) VALUES ('$username','$fullname','$email','','$age','$password','$gender','$occupation','Surveyee')");
            if(!$insert){
                echo mysqli_errno();
            }
            else{
                echo '<script language="javascript">';
                echo 'alert("Registration Success!")';
                echo '</script>';
            }
        }
    }
}
?>

<div id="surveyeesignup" class="modal" tabindex="1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" id="close" class="close" data-dismiss="modal">&times;</button>
                <h3 class="modal-title">Sign Up</h3>
            </div>

            <div class="modal-body">
                <div class="row">

                    <form action="#" method="POST">

                        <div class="row form-group">
                            <div class="col-sm-12">
                                <input type="text" name="username"  id="username" class="form-control" placeholder="Username">
                            </div>
                        </div>

                        <div class="row form-group">
                            <div class="col-sm-12">
                             <input type="text" name="fullname"  id="fullname" class="form-control" placeholder="Fullname">
                            </div>
                        </div>

                        <div class="row form-group">
                            <div class="col-sm-12">
                                <input type="email" name="email" id="email" class="form-control" placeholder="Email">
                            </div>
                        </div>

                        <div class="row form-group">
                            <div class="col-sm-12">
                                <input type="text" name="age"  id="age" class="form-control" placeholder="Age" pattern="[0-9]+">
                            </div>
                        </div>


                        <div class="row form-group">
                            <div class="col-sm-12">
                                <input type="password" name="password" id="password" class="form-control" placeholder="Password">
                            </div>
                        </div>

                        <div class="row form-group">
                            <div class="col-sm-12">
                                <input type="password" name="confirmpassword" id="confirmpassword" class="form-control" placeholder="Confirm Password">
                            </div>
                        </div>

                        <div class="row form-group">
                            <div class="col-sm-12">
                                <input type="radio" class="" name="gender" value="male" placeholder="">
                                <label>Male</label>

                                <input type="radio" class="" name="gender" value="female" placeholder="">
                                <label>Female</label>
                            </div>
                        </div>

                        <div class="row form-group">
                            <p style="float: right; margin-right: 180px;"><b>Select Occupation:</b> <select name="occupation"></p>
                                <option>Student</option>
                                <option>Employed</option>
                                <option>Unemployed</option>
                            </select>
                        </div>

                        <div class="row form-group">
                            <div class="col-sm-12">
                                <input type="submit" name="submit" id="sign_up" class="form-control btn btn-primary" value="Sign Up">
                            </div>
                        </div>





                    </form>

                </div>

            </div>

            <div class="modal-footer">
                <p class="text-center">Already have an account? <a href="">Login</a></p>


            </div>

        </div>

    </div>

</div>

1 个答案:

答案 0 :(得分:0)

最好的方法是为每个表单设置不同的操作并创建单独的脚本。

<form action="sign-up.php">

(顺便说一句,你的代码很容易受到SQL注入)