PHP form validation not working as expected [duplicate]

匆匆过客 提交于 2020-01-22 02:29:04

问题


I'm a bit new to php and I was going over a tutorial where they are making validation form, but when I try and replicate what they do I don't get the same as them, when they run the code, the input box shows up red because the user hasn't placed anything in the input box. When I try it, nothing happens, the input box doesn't show me any errors.

But when I try and submit my form with data it just sends me to the next page, and if I dont type anything I just stay in the same page.

All this code is inside index.php

    if(($_POST['email']) != "")
    {
        header('Location:final.php');
    }
    else{
        $emailError = "validation";
    }

<form method="post" action="index.php" >

<!--Get warning here when no input is placed-->
<div class="<?=$emailError?>">
   <label>E-mail Address:</label>
   <input type="text" name="email">
</div>

来源:https://stackoverflow.com/questions/59377911/php-form-validation-not-working-as-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!