PHP提交请求不起作用

PHP提交请求不起作用,php,Php,我创建了一个注册用户系统,分为两页。(registercontrol.php和register.php) 在register.php中,通常“Submit”按钮会将数据发送到registercontrol.php,但当我单击Submit按钮时,不会发生任何事情。它只是刷新页面,什么也不做,成员表中没有数据。我错过什么了吗 register.php <?php require('../includes/config.php'); //if logged in redirect to m

我创建了一个注册用户系统,分为两页。(registercontrol.php和register.php)

在register.php中,通常“Submit”按钮会将数据发送到registercontrol.php,但当我单击Submit按钮时,不会发生任何事情。它只是刷新页面,什么也不做,成员表中没有数据。我错过什么了吗

register.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

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

registercontrol.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

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

您缺少一个表单元素,它的
操作
方法
属性设置为您的其他脚本,并设置为
post
。在这种情况下,
action
应该是
registercontrol.php
。 在不设置操作的情况下,表单提交给它自己,在本例中是
register.php

类似这样的东西应该可以解决问题(只添加了第一行和最后一行,其余的是您的代码):


您缺少一个表单元素,它的
操作
方法
属性设置为您的其他脚本,并设置为
post
。在这种情况下,
action
应该是
registercontrol.php
。 在不设置操作的情况下,表单提交给它自己,在本例中是
register.php

类似这样的东西应该可以解决问题(只添加了第一行和最后一行,其余的是您的代码):