2017-10-20 34 views
-1

所以我有一个登录/注册页面,这是注册码:数据没有被添加到mysql表,但回声的数据?

<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"); 
    } 

} 

但它似乎没有将它添加到我的数据库中,我已检查它可以连接,它也可以回显已插入表单中的值,但它不会将它们添加到表中,并且不会将它们添加到表中似乎是来自数据库或代码的任何错误消息,我得到的唯一错误消息是我在注册失败时创建的错误消息。

这些都是在表中的字段:

unique_id | FirstName | LastName | nickname | Email | password | hash | account_type | active 

回答

2

变化first_namelast_nameFirstNameLastName,因为你在表字段使用FirstNameLastName

$sql = "INSERT INTO logins (FirstName, LastName, nickname, Email, password, hash, account_type) " 
     . "VALUES ('$first_name','$last_name', '$nickname', '$email','$password', '$hash', '$account_type')"; 

Email

相关问题