當所有其他功能的工作我的註冊頁面上設置名稱,用戶名,電子郵件,密碼都在工作,但是當他們輸入他們的名字,它並沒有在MySQL數據庫顯示。註冊
還有我的SQL數據庫的建立,我會建立什麼了嗎?
這裏是我的代碼爲我的註冊頁面
<div class="login-box center">
<div class="white-box">
<form class="form-horizontal m-t-20" method="post" action="" autocomplete="off">
<div class="form-group ">
<div class="col-xs-12">
<h3>Sign Up</h3>
</div>
</div>
<div class="form-group ">
<div class="col-xs-12">
<input class="form-control" id="name" name="name" type="text" required="" placeholder="Name">
</div>
</div>
<div class="form-group ">
<div class="col-xs-12">
<input class="form-control" id="username" name="username" type="text" required="" placeholder="Username">
</div>
</div>
<div class="form-group ">
<div class="col-xs-12">
<input class="form-control" id="email" name="email" type="text" required="" placeholder="Email">
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<input class="form-control" id="password" name="password" type="password" required="" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<input class="form-control" id="passwordConfirm" name="passwordConfirm" type="password" required="" placeholder="Confirm Password">
</div>
</div>
<div class="form-group ">
<div class="col-xs-12">
<div class="checkbox checkbox-primary">
<input id="checkbox-signup" type="checkbox">
<label for="checkbox-signup"> By clicking Sign Up, you agree to our <a href="#">Terms</a> </label>
</div>
</div>
</div>
<div class="form-group text-center m-t-40">
<div class="col-xs-12">
<button class="btn btn-boom btn-login btn-lg btn-block text-uppercase waves-effect waves-light" name="submit" type="submit">Sign Up</button>
</div>
</div>
插入代碼:
<?php require('includes/config.php');
//if logged in redirect to members page
if($user->is_logged_in()){ header('Location: memberpage.php'); }
//if form has been submitted process it
if(isset($_POST['submit'])){
//very basic validation
if(strlen($_POST['username']) < 3){
$error[] = 'Username is too short.';
} else {
$stmt = $db->prepare('SELECT username FROM members WHERE username = :username');
$stmt->execute(array(':username' => $_POST['username']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if(!empty($row['username'])){
$error[] = 'Username provided is already in use.';
}
}
if(strlen($_POST['password']) < 3){
$error[] = 'Password is too short.';
}
if(strlen($_POST['passwordConfirm']) < 3){
$error[] = 'Confirm password is too short.';
}
if($_POST['password'] != $_POST['passwordConfirm']){
$error[] = 'Passwords do not match.';
}
//email validation
if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
$error[] = 'Please enter a valid email address';
} else {
$stmt = $db->prepare('SELECT email FROM members WHERE email = :email');
$stmt->execute(array(':email' => $_POST['email']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if(!empty($row['email'])){
$error[] = 'Email provided is already in use.';
}
}
選擇:
//Name Validation
if(!filter_var($_POST['name'], FILTER_VALIDATE_EMAIL)){
$error[] = 'Please enter Your Name';
} else {
$stmt = $db->prepare('SELECT name FROM members WHERE name = :name');
$stmt->execute(array(':name' => $_POST['name']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
}
}
//if no errors have been created carry on
if(!isset($error)){
//hash the password
$hashedpassword = $user->password_hash($_POST['password'], PASSWORD_BCRYPT);
//create the activasion code
$activasion = md5(uniqid(rand(),true));
try {
//insert into database with a prepared statement
$stmt = $db->prepare('INSERT INTO members (name,username,password,email,active) VALUES (:username, :password, :email, :active, :name)');
$stmt->execute(array(
':name' => $_POST['name'],
':username' => $_POST['username'],
':password' => $hashedpassword,
':email' => $_POST['email'],
':active' => $activasion
));
$id = $db->lastInsertId('memberID');
//send email
$to = $_POST['email'];
$subject = "Registration Confirmation";
$body = "<p>Thank you for registering at BigFellaHQ.</p>
<p>To activate your account, please click on this link: <a href='".DIR."activate.php?x=$id&y=$activasion'>".DIR."activate.php?x=$id&y=$activasion</a></p>
<p>Regards BigFellaHQ Admin</p>";
$mail = new Mail();
$mail->setFrom(SITEEMAIL);
$mail->addAddress($to);
$mail->subject($subject);
$mail->body($body);
$mail->send();
//redirect to index page
header('Location: login.php?action=joined');
exit;
//else catch the exception and show the error.
} catch(PDOException $e) {
$error[] = $e->getMessage();
}
}
}
?>
請提供您的SQL'INSERT'聲明。你可能有問題。 –
在哪裏註冊頁面的PHP代碼? –
貌似我忘了補充MySQL的插入在我的PHP – BigFella