简体   繁体   中英

I dont get Submit button when i press register (register/login system php)

So i made a register form and it works all fine except when i press register it should give me back Submited but it doesnt i dont know why is there a mistake in the code cuz i dont see it please help me out here..

register.php:

<?php

require_once 'core/init.php';

if(input::exists()) {
echo 'Submitted';
}

?>


<form action="" method="">
    <div class="field">
        <label for="username">Username</label>
        <input type="text" name="username" id="username" value="" autocomplete="off">
    </div>

    <div class="field">
        <label for="password">Create a password</label>
        <input type="password" name="password" id="password">
    </div>

    <div class="field">
        <label for="password_again">Enter your password again</label>
        <input type="password" name="password_again" id="password_again">
    </div>

    <div class="field">
        <label for="name">Enter your password again</label>
        <input type="text" name="name" id="name">
    </div>

    <input type="submit" value="Register"

input.php:

<?php
class input {
    public static function exists($type = 'post') {
        switch($type) {
            case 'post':
                return (!empty($_POST)) ? true : false;
            break;
            case 'get':
                return (!empty($_GET)) ? true : false;
            break;
            default:
                return false;
            break;
        }
    }
}

and init.php

<?php
session_start();

$GLOBALS ['config'] = array(
    'mysql' => array(
        'host' => '127.0.0.1',
        'username' => 'root',
        'password' => '',
        'db' => 'lr'
    ),
    'remember' => array(
        'cookie_name' => 'hash',
        'cookie_expiry' => 604800
        ),
    'session' => array(
        'session_name' => 'user'
    )
);

spl_autoload_register(function($class) {
    require_once 'classes/' . $class . '.php';

});

require_once 'functions/sanitize.php';
?>

The button was not closed

you have

<input type="submit" value="Register"

should be

<input type="submit" value="Register">

More over the form needs to be closed

</form>

Also You have form action="" this will need $_GET["username"] etc to get the values In the function exists() default type is post so u will need to set the form method as post or while calling the

if(input::exists()) {
echo 'Submitted';
}

you should do as

if(input::exists("get")) {
echo 'Submitted';
}

So in the 2nd case you can keep the form action as ""

i found the problem

<form action="" method=""> 

forgot to put post in it

<form action="" method="post">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM