为什么echo不能在这个脚本中工作?

时间:2014-02-27 22:53:06

标签: php html mysql

我在php oop中创建登录和注册配置文件。我正在关注YouTube上的一个教程,并试着在我去的时候理解它。我有一个部分,我很难过为什么它不会像在youtube视频上那样回应。我已经对代码进行了三次检查,所有内容都与视频中显示的相同,到目前为止一切都运行正常。

所以我的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 '';
}
}
?>

我的register.php代码:

<?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>

当视频按下注册提交按钮时,回声'已提交'但我的并没有将网址更改为: 我在当地主持人:

mylogin / register.php用户名=安培;密码=安培; password_again =安培;名称

^希望所需的所有信息。干杯

2 个答案:

答案 0 :(得分:6)

您的PHP默认使用$_POST数据载体,但由于此错误,您的表单是通过$_GET提交的:

method"post"

应该......

method="post"

答案 1 :(得分:3)

<form action="" method"post">

应该是

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

注意方法和帖子之间的“=”。

相关问题