RandomViewing
RandomViewing

Reputation: 31

why is echo not working in this script?

Im creating a login and register profile in php oop. Im following one of the tutorials on YouTube and trying to understand it as I go. I have got to one section and im stumped as to why its not echoing like it does on the youtube video. I have triple checked the code and everything is the same as it shows in the video, up to now everything has worked fine.

So my code for 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;
    }
}

public static function get($item) {
    if(isset($_POST[$item])) {
        return $_POST[$item];
    } else if(isset($_GET[$item])) {
        return $_GET[$item];
    }
    return '';
}
}
?>

My register.php code:

<?php
require_once 'core/init.php';

if(Input::exists()) {
echo Input::get('username');
}
?>
<form action="" method"post">
<div class="field">
    <label for="username">Username:</label>
    <input type="text" name="username" id="username" autocomplete="off">
</div>
<div class="field">
    <label for="password">Password:</label>
    <input type="password" name="password" id="password">
</div>
<div class="field">
    <label for="password_again">Password:</label>
    <input type="password" name="password_again" id="password_again">
</div>
<div class="field">
    <label for="name">Name:</label>
    <input type="text" name="name" id="name">
</div>
<div class="field">
    <input type="submit" value="Register">
</div>
</form>

When the video presses register submit button it echos 'submitted' but mine doesnt it changes the url to: im on a local host:

mylogin/register.php?username=&password=&password_again=&name

^ hope thats all the information needed. Cheers

Upvotes: 1

Views: 132

Answers (2)

DragonYen
DragonYen

Reputation: 968

<form action="" method"post">

should be

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

note the "=" between method and post.

Upvotes: 3

Mark Ormesher
Mark Ormesher

Reputation: 2408

Your PHP defaults to using the $_POST data carrier, but your form is being submitted via $_GET because of this error:

method"post"

Should be...

method="post"

Upvotes: 6

Related Questions