我試圖創建一個簡單的註冊頁面,但我的提交按鈕似乎沒有工作時單擊。註冊PHP頁面不工作,我不知道爲什麼
我確定配置文件是正確的,我希望有人能告訴我我的錯誤。非常感謝你。
這裏是我的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="[email protected]">
</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>
還有其他標點字符比感嘆號!到目前爲止,您已經完成了哪些調試? – CBroe
@JustBaron可能更傾向於'method'屬性,因爲默認值是GET。 – CBroe
在'form'標籤中給出'method'和'action'屬性 – KMS