我的表单数据没有发布,因为某些原因我甚至无法进入第一个if语句。我一直在寻找,似乎找不到符合我问题的人的答案。
<?php
$pagetitle = "Registration Form";
require "header.php";
//NEEDED VARIABLES & INCLUDES
//$errormsg = "";
$fnameError ="";
$lnameError = '';
$usrnameError = '';
$emailError = '';
$pwdError='';
//$valid = true;
if(isset($_POST['submit'])&& !empty($_POST['submit']))
{
echo 'here';
/* ****************************************************************************
CREATE NEW VARS TO STORE USER DATA & SANITIZE DATA FROM USER.
************************************************************************* */
$formfield['fname'] = trim(strtolower($_POST['first']));
$formfield['usrname'] = trim(strtolower($_POST['uname']));
$formfield['pwd'] = trim($_POST['pwd']); //we never force a lowercase password
$formfield['pwd2'] = trim($_POST['pwd2']); //we never force a lowercase password
//REGEX Validation
if(empty($_POST['fname']))
{
$fnameError = "You must enter a first name.";
$valid = false;
}
elseif((!preg_match("/[\w\s\-]+/", $_POST['first_name']) || !preg_match("/^[a-zA-Z]/", $_POST['fname'])))
{
$fnameError = "Invalid first name.";
$valid = false;
}
if(empty($_POST['lname']))
{
$lnameError = 'You must enter a last name';
$valid = false;
}
elseif(!preg_match("/[\w\s\-]+/", $_POST['lname']) || !preg_match("/^[a-zA-Z]/", $_POST['lname']))
{
$lnameError = "Invalid last name.";
$valid = false;
}
if(empty($_POST['email']))
{
$emailError = 'You must enter an email.';
$valid = false;
}
elseif(!preg_match("/@/", $_POST['email']))
{
$emailError = 'Invalid email';
$valid = false;
}
if(empty($_POST['pwd']))
{
$pwdError = 'You must enter a password.';
$valid = false;
}
elseif($_POST['pwd'] != $_POST['pwd2'])
{
$pwdError = "Passwords did not match.";
$valid = false;
}
elseif(!preg_match("/.{6}/", $_POST['pwd']))
{
$pwdError = 'Password must be longer than 6 characters.';
$valid = false;
}
/* ****************************************************************************
CHECK FOR DUPLICATE USERS
************************************************************************* */
try
{
$sqlusers = "SELECT * FROM users WHERE usrname = :usrname";
$stmtusers = $pdo->prepare($sqlusers);
$stmtusers->bindValue(':usrname', $formfield['usrname']);
$stmtusers->execute();
$countusers = $stmtusers->rowCount();
if ($countusers > 0)
{
$usrnameError = "Username already taken";
}
}
catch (PDOException $e)
{
echo "<div class='error'><p></p>ERROR selecting users!" .$e->getMessage() . "</p></div>";
exit();
}
/* ****************************************************************************
HASH THE PASSWORD
**************************************************************************** */
$securepwd = password_hash($formfield['pwd'], PASSWORD_DEFAULT);
/* ****************************************************************************
CONTROL FOR ERRORS. IF ERRORS, DISPLAY THEM. IF NOT, CONTINUE WITH FORM PROCESSING.
**************************************************************************** */
try
{
$sql = "INSERT INTO users(id, fname, lname, pwd, email, usrname, question, questionAnswer)
VALUES (5,'penis',[value-3],[value-4],[value-5],[value-6],[value-7],[value-8])";
$stmt = $pdo->prepare($sql);
$stmt->bindvalue(':fname', $formfield['fname']);
$stmt->bindvalue(':usrname', $formfield['usrname']);
$stmt->bindvalue(':pwd', $securepwd);
$stmt->execute();
$showform=0; //hide the form
echo "<div class='success'><p>There are no errors. Thank you for registering.</p></div>";
}//try
catch(PDOException $e)
{
echo "<div class='error'><p>ERROR inserting data into the database!" .$e->getMessage() . "</p></div>";
exit();
}
//else errors
}//isset submit ?>
我不知道发生了什么,这是HTML代码
<div class="container">
<div class="jumbotron">
<form method="post" action="">
<div class="form-group">
<label for="fname">First Name: </label><span style="font-size: small; color: red"><?php echo $fnameError?></span>
<input type="text" class="form-control" id="fname" name="fname">
</div>
<div>
<label for="lname">Last Name: </label><span style="font-size: small; color: red"><?php echo $lnameError?></span>
<input type="text" class="form-control" id="lname" name="lname">
</div>
<div>
<label for="email">Email: </label><span style="font-size: small; color: red"><?php echo $emailError?></span>
<input type="email" class="form-control" id="email" name="email">
</div>
<div>
<label for="usrname">Username: </label><span style="font-size: small; color: red"><?php echo $usrnameError?></span>
<input type="text" class="form-control" id="usrname" name="usrname">
</div>
<div>
<label for="question">Security Question: </label>
<input type="text" class="form-control" id="question" name="question" >
<input type="text" class="form-control" id="questionAnswer" name="questionAnswer">
</div>
<label for="pwd">Password: </label><?php echo $pwdError?>
<input type="password" class="form-control" id="pwd" name="pwd">
<label for="pwd2">Confirm: </label><?php echo $pwdError?>
<input type="password" class="form-control" id="pwd2" name="pwd2">
<button type="submit" class="btn-default" value="Submit" name="Submit">Register</button>
</form>
</div>