在输入值中添加echo时未定义的变量

时间:2017-05-26 09:33:48

标签: php html

你能告诉我为什么会这样吗?我有一个简单的表单,输入类型有值echo,但加载网站时,我得到Undefined Variable。继承我的代码:

<?php 

    ob_start();
    session_start();

    require_once '../config.php';
    require_once "include/lib.php";


    //* run if button submit trigger
    if ( isset($_POST['btn-add-new']) ) {

        //* clean user inputs to prevent sql injections
        $username = trim($_POST['username']);
        $username = strip_tags($username);
        $username = htmlspecialchars($username);

        $email = trim($_POST['email']);
        $email = strip_tags($email);
        $email = htmlspecialchars($email);      

    }

?>

<div class="right_col" role="main">
    <div class="row">

        <form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" autocomplete="off">

            <?php if ( isset($errMSG) ) { ?>
            <div class="form-group">
                <div class="alert alert-<?php echo ($errTyp=="success") ? "success" : $errTyp; ?>">
                    <span class="glyphicon glyphicon-info-sign"></span> <?php echo $errMSG; ?>
                </div>
            </div>
            <?php } ?>

            <div class="form-group">
                <label>Username</label>
                <input type="text" name="username" placeholder="Username" value="<?php echo $username; ?>" maxlength="20">
                <span class="text-danger"><?php echo $usernameError; ?></span>
            </div>

            <div class="form-group">
                <label>Email</label>
                <input type="email" name="email" placeholder="Email" value="<?php echo $email; ?>">
                <span class="text-danger"><?php echo $emailError; ?></span>
            </div>

            <div class="form-group">
                <button type="submit" name="btn-add-new">Add New User</button>
            </div>

        </form>

    </div>
</div>
<?php ob_end_flush(); ?>

下面是错误的截图: enter image description here

0 个答案:

没有答案