注册php页面不起作用,我不知道为什么

时间:2017-09-15 10:46:33

标签: php html mysql

我正在尝试创建一个简单的注册页面,但单击时我的提交按钮似乎不起作用。

我确定配置文件是正确的,我希望有人可以告诉我我的错误。非常感谢你。

这是我的sql表:

CREATE TABLE `THANHVIEN` (
  `id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `username` varchar(50) NOT NULL,
   `password` varchar(50) NOT NULL,
   `email` varchar(50) DEFAULT NULL,
   `fullname` varchar(80) DEFAULT NULL,
   `birthday` date DEFAULT NULL,
   `gender` int(1) DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

这是我的HTML / PHP:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Private Exercise</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<?php
        session_start();
        require_once('config.php');
        if(isset($_POST['submit'])){
            $username = $_POST['username'];
            $password = md5($_POST['password']);
            $email = $_POST['email'];
            $fullname = $_POST['fullname'];
            $birthday = $_POST['birthday'];
            $gender = $_POST['gender'];
            if($username == "" || $password == "" || $email == "" || $fullname == "" || $birthday == "" || $gender == ""){
                $message = "Xin vui lòng điền lại đầy đủ thông tin";
                exit;
            }
            if (mysql_num_rows(mysql_query("SELECT username FROM member WHERE username='$username'")) > 0){
                $message="Tên đăng nhập đã có người dùng rồi. <a href='javascript: history.go(-1)'>Trở lại</a>";
                exit;
            }
            if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email))
            {
                $message="Email này không hợp lệ, vui lòng nhập email khác. <a href='javascript: history.go(-1)'>Trở lại</a>";
                exit;
            }
            if (mysql_num_rows(mysql_query("SELECT email FROM member WHERE email='$email'")) > 0)
            {
                $message="Email này đã có người dùng rồi, vui lòng nhập Email khác. <a href='javascript: history.go(-1)'>Trở lại</a>";
                exit;
            }

                $query = "INSERT INTO `THANHVIEN` (username, password, email, fullname, birthday, gender) VALUES ('$username', '$password', '$email', '$fullname', '$birthday', '$gender')";
                 @$register=$conn->query($query);
                if ($register)
                    $message="Đăng ký thành công. <a href='/edit.php'>Về trang cá nhân</a>";
                else
                    $message="Có lỗi trong quá trình đăng ký. <a href='dangky.php'>Thử lại</a>";
                exit;

    }
    ?>

<form class="form-horizontal">

  <div class="form-group">
  <span class="text-danger"><?php echo $message ?></span>

    <label class="control-label col-sm-2" for="username">USERNAME:</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" name="username" id="username" placeholder="ENTER USERNAME">
    </div>
  </div>
  <div class="form-group">
    <label class="control-label col-sm-2" for="password">PASSWORD:</label>
    <div class="col-sm-10"> 
      <input type="password" class="form-control" name="password" id="password" placeholder="Enter password">
    </div>
  </div>
  <div class="form-group">
    <label class="control-label col-sm-2" for="email">EMAIL:</label>
    <div class="col-sm-10"> 
      <input type="email" class="form-control" name="email" id="email" placeholder="vidu@email.com">
    </div>
  </div>
  <div class="form-group">
    <label class="control-label col-sm-2" for="fullname">FULLNAME:</label>
    <div class="col-sm-10"> 
      <input class="form-control" name="fullname" id="fullname" placeholder="NGUYEN VAN A">
    </div>
  </div>
  <div class="form-group">
    <label class="control-label col-sm-2" for="birthday">BIRTHDAY:</label>
    <div class="col-sm-10"> 
      <input type="date" class="form-control" name="birhday" id="password">
    </div>
  </div>
  <div class="form-group">
    <label class="control-label col-sm-2" for="gender">GENDER:</label>
    <div class="col-sm-10">
            <select name="gender" id="gender" class="form-control">
              <option value="0">Male</option>
              <option value="1">Female</option>
            </select>
    </div>
  </div>
  <div class="form-group"> 
    <div class="col-sm-offset-2 col-sm-10">
     <button type="submit" name="submit" id="submit" class="btn btn-success">Submit</button>
    </div>
  </div>
</form>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

致KMS的信用

将表单标记从此<form class="form-horizontal" method="POST" action="index.php">更改为此{{1}}

您正在寻找一个不存在的帖子变量。

希望这有帮助