我想帮助解决为什么用户信息没有插入数据库的原因。我没有在屏幕上显示任何错误,当我为数据库中尚未存在的用户输入信息时,回显“命中”,因此它正在到达该代码块,而不是插入到数据库中。
当我回复$ query我输入的值时,我收到了INSERT INTO用户(first_name,last_name,email,密码)VALUES('tanya','long','tlong3 @twc.com','purple03')没有出现当我回应$ result谢谢
<?php
session_start();
require_once("/includes/registerFunctions.php");
require("/includes/databaseConnection.php");
?>
<?php
$name_message = "";
$password_message = "";
$email_message = "";
$missingInfo = "<div class='message'> Please fix the following errors: ". "<br>"."<ul>";
$numOfErrors = 0;
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST) && isset($_POST['submit']))
{
$first_name = mysqli_real_escape_string($connect, $_POST['fname']);
$last_name = mysqli_real_escape_string($connect, $_POST['lname']);
$email = mysqli_real_escape_string($connect,$_POST['email']);
$password = mysqli_real_escape_string($connect, $_POST['password']);
$confirm_password = mysqli_real_escape_string($connect, $_POST['cpassword']);
$content = array($first_name, $last_name, $email, $password, $confirm_password);
$contentMessage = array("First name", "Last name", "email", "password", "confirmation password");
$length = count($content);
if(!equalPasswords($password, $confirm_password))
{
$missingInfo .= "<li> Passwords do not match </li>";
$numOfErrors++;
}
if(!valid_email($email))
{
$missingInfo .= "<li>The entered email is invalid. </li>";
$numOfErrors++;
}
$min = 8;
if(strlen($password) < $min || strlen($confirm_password) < $min)
{
$missingInfo .= "<li>Please choose a password that is at least ". $min ." characters long </li>";
$numOfErrors++;
}
for($i = 0; $i < $length; $i++)
{
if(!has_presence($content[$i]))
{
$missingInfo .= "<li>". ucfirst($contentMessage[$i])." is blank "."<br> </li>";
$numOfErrors++;
}
}
$missingInfo .= "</ul></div>";
if($numOfErrors > 0)
{
echo $missingInfo;
}
$emailQuery = "SELECT email FROM users WHERE email = '$email'";
$emailResult = mysqli_query($connect, $emailQuery);
$numOfRows = mysqli_num_rows($emailResult);
if($numOfErrors == 0 && $numOfRows == 0)
{
/* Check if the email is already in use*/
echo "Hit";
$query = "INSERT INTO users (";
$query .= " first_name, last_name, email, password";
$query .= ") VALUES (";
$query .= " '{$first_name}', '{$last_name}', '{$email}', '{$password}'";
$query .= ")";
$result = mysqli_query($connect, $query);
if($result)
{
$_SESSION['fname'] = $first_name;
$_SESSION['lname'] = $last_name;
}
//$userId = $_SESSION['id'];
}
else if($numOfRows >= 1 )
{
echo "The email entered is already in use, please : ". "<a href='index.php'>login</a>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title> Register</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="register.css">
<link href="https://fonts.googleapis.com/css?family=Amatic+SC" rel="stylesheet">
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">
<style type="text/css">
form{
padding-top: 20px;
text-align: center;
}
.message
{
position: absolute;
right: 180px;
top: 60px;
width: 220px;
}
input {
border: 0;
outline: 0;
background: transparent;
border-bottom: 1px solid grey;
width: 250px;
}
div
{
padding: 10px;
}
a
{
color: #4169E1;
}
a:hover{
color:grey;
}
</style>
</head>
<body>
<form id="form" method="POST" action="register.php">
<h3 style="font-family:'Amatic SC', cursive; font-size: 20px;"> Welcome to Caruize </h3>
<div >
<input type="text" name="fname" id="fname" placeholder="First Name" autocomplete="off">
</div>
<div >
<input type="text" name="lname" id="lname" placeholder="Last Name" autocomplete="off" required>
</div>
<div >
<input type="email" name="email" id="email" placeholder="Email Address" autocomplete="off" required>
</div>
<div>
<input type="password" name="password" id="password" placeholder="Password" autocomplete="off" required>
</div>
<div>
<input type="password" name="cpassword" id="cpassword" placeholder="Confirm Password" autocomplete="off" required>
</div>
<div>
<button type="submit" name="submit" class="pure-button pure-button-primary"> Register</button> <br> <br>
<p> Already a member? </p><a style="text-decoration: none;" href="index.php">Sign in </a>
</div>
</form>
<script type="text/javascript">
var pLabel = document.getElementById("passwordLabel");
pLabel.textContent = "Too Short";
</script>
</body>
</html>
答案 0 :(得分:0)
哈哈,我只是将值插入到表单所需的数据库中。哈哈有大约5个其他字段,我设置为NOT NULL,我没有插入哈哈。谢谢你们。