所以我有一个登录/注册页面,这是注册码:
<div id="signup">
<h1>Sign Up for Free</h1>
<form action="index.php" method="post" autocomplete="off">
<div class="top-row">
<div class="field-wrap">
<label>
First Name<span class="req">*</span>
</label>
<input type="text" required autocomplete="off" name='FirstName' />
</div>
<div class="field-wrap">
<label>
Last Name<span class="req">*</span>
</label>
<input type="text"required autocomplete="off" name='LastName' />
</div>
</div>
<div class="field-wrap">
<label>
Username<span class="req">*</span>
</label>
<input type="text"required autocomplete="off" name='nickname' />
</div>
<div class="field-wrap">
<label>
Email Address<span class="req">*</span>
</label>
<input type="email"required autocomplete="off" name='Email' />
</div>
<div class="field-wrap">
<label>
Set A Password<span class="req">*</span>
</label>
<input type="password"required autocomplete="off" name='password'/>
</div>
<div class="field-wrap">
<label class="custom-control custom-radio">
<input id="PUBLIC" name="account_type" value="PUBLIC" type="radio" class="custom-control-input">
<span class="custom-control-indicator" style="pointer-events: all;"></span>
<span class="custom-control-description">Public</span>
</label>
<label class="custom-control custom-radio">
<input id="PRIVATE" name="account_type" value="PRIVATE" type="radio" class="custom-control-input">
<span class="custom-control-indicator" style="pointer-events: all;"></span>
<span class="custom-control-description">Private</span>
</label>
</div>
<button type="submit" class="button button-block" name="register" />Register</button>
</form>
</div>
</div><!-- tab-content -->
</div> <!-- /form -->
这与注册用户数据的注册php页面相关联:
<?php
/* Registration process, inserts user info into the database
and sends account confirmation email message
*/
require 'db.php';
global $mysqli;
// Set session variables to be used on profile.php page
$_SESSION['Email'] = $_POST['Email'];
$_SESSION['FirstName'] = $_POST['FirstName'];
$_SESSION['LastName'] = $_POST['LastName'];
// Escape all $_POST variables to protect against SQL injections
$first_name = $mysqli->escape_string($_POST['FirstName']);
$last_name = $mysqli->escape_string($_POST['LastName']);
$nickname = $mysqli->escape_string($_POST['nickname']);
$email = $mysqli->escape_string($_POST['Email']);
$password = $mysqli->escape_string(password_hash($_POST['password'], PASSWORD_BCRYPT));
$hash = $mysqli->escape_string( md5( rand(0,1000) ) );
$account_type = $mysqli->escape_string($_POST['account_type']);
// Check if user with that email already exists
$result = $mysqli->query("SELECT * FROM logins WHERE email='$email'") or die($mysqli->error());
// We know user email exists if the rows returned are more than 0
if ( $result->num_rows > 0 ) {
$_SESSION['message'] = 'User with this email already exists!';
header("location: error.php");
}
else { // Email doesn't already exist in a database, proceed...
// active is 0 by DEFAULT (no need to include it here)
$sql = "INSERT INTO logins (first_name, last_name, nickname, email, password, hash, account_type) "
. "VALUES ('$first_name','$last_name', '$nickname', '$email','$password', '$hash', '$account_type')";
// Add user to the database
if ( $mysqli->query($sql) ){
$_SESSION['active'] = 0; //0 until user activates their account with verify.php
$_SESSION['logged_in'] = true; // So we know the user has logged in
$_SESSION['message'] =
"Confirmation link has been sent to $email, please verify
your account by clicking on the link in the message!";
// Send registration confirmation link (verify.php)
$to = $email;
$subject = 'Account Verification ( Reps&Steps )';
$message_body = '
Hello '.$first_name.',
Thank you for signing up!
Please click this link to activate your account:
http://repsandsteps/login-system/verify.php?email='.$email.'&hash='.$hash;
mail( $to, $subject, $message_body );
header("location: profile.php");
}
else {
$_SESSION['message'] = 'Registration failed!';
header("location: error.php");
}
}
但它似乎没有将它添加到我的数据库中,我已经检查过它可以连接,它也可以回显已经插入到表单中的值,但它刚刚赢了& #39; t将它们添加到表中并且似乎不是来自数据库或代码的任何错误消息,我得到的唯一错误消息是我在注册失败时创建的错误消息。
这些是表格中的字段:
unique_id | FirstName | LastName | nickname | Email | password | hash | account_type | active
答案 0 :(得分:2)
将first_name
和last_name
更改为FirstName
和LastName
,因为表格中的字段使用FirstName
和LastName
$sql = "INSERT INTO logins (FirstName, LastName, nickname, Email, password, hash, account_type) "
. "VALUES ('$first_name','$last_name', '$nickname', '$email','$password', '$hash', '$account_type')";
也是Email