我创建了一个注册用户系统并分为两个页面。(registercontrol.php 和 register.php)
在register.php中,通常“提交”按钮应该将数据发送到registercontrol.php,但是当我单击“提交”按钮时没有任何反应。它只是刷新页面,什么也不做,成员表中没有数据。我错过了什么吗?
注册.php
<?php
require('../includes/config.php');
//if logged in redirect to members page
if ($user->is_logged_in() ){
header('Location: ../dashboard/index.php');
exit();
}
//define page title
$title = 'Demo';
//include header template
require('../layout/header.php');
?>
<input type="text" name="fullname" id="fullname" class="form-control form-control-user" placeholder="Your Name" value="<?php if(isset($error)){ echo htmlspecialchars($_POST['fullname'], ENT_QUOTES); } ?>" tabindex="1" required>
<?php
//check for any errors
if (isset($infofn)){
foreach ($infofn as $infofn){
echo '<p class="p-3 text-info">'.$infofn.'</p>';
}
}
?>
<input id="submit" type="submit" name="submit" value="Create Account" class="btn btn-primary btn-user btn-block" tabindex="6">
注册控制.php
<?php
require('../includes/config.php');
if(isset($_POST['fullname'])){
//fullname validation
$fullname = $_POST['fullname'];
if (! $user->isValidFullname($fullname)){
$infofn[] = 'Your name must be alphabetical characters';
}
}
//if form has been submitted process it
if(isset($_POST['submit'])){
//if no errors have been created carry on
if (!isset($infofn)){
try {
//insert into database with a prepared statement
$stmt = $db->prepare('INSERT INTO members (fullname) VALUES (:fullname)');
$stmt->execute(array(
':fullname' => $fullname
));
$id = $db->lastInsertId('memberID');
//redirect to index page
header('Location: register.php?action=joined');
exit;
//else catch the exception and show the error.
} catch(PDOException $e) {
$error[] = $e->getMessage();
}
}
}
扬帆大鱼