使用PHP验证字段,使其赢得';你不能进入另一页吗?

使用PHP验证字段,使其赢得';你不能进入另一页吗?,php,validation,Php,Validation,我想知道如何使用PHP验证html表单中的字段,这样当我单击“提交”按钮时,在所有字段都有效之前,它不会前进到另一个页面?在服务器端使用if语句,类似于 if($POST['txt'] != ''){ // validation successful, redirect user } else { // validation failed, alert user } PHP在服务器端运行-您需要使用Javascript验证表单。将Javascript用于类似jquery val

我想知道如何使用PHP验证html表单中的字段,这样当我单击“提交”按钮时,在所有字段都有效之前,它不会前进到另一个页面?

在服务器端使用if语句,类似于

if($POST['txt'] != ''){
    // validation successful, redirect user
}
else
{
    // validation failed, alert user
}

PHP在服务器端运行-您需要使用Javascript验证表单。将Javascript用于类似jquery validator插件的前端。。用于服务器端脚本的php作为澄清,您的意思是“根本不加载新页面”还是“如果验证失败,则不加载新页面”?根据评论和回答,我们不确定是哪一个。我认为这是第二个,在这种情况下,使用服务器端验证就可以了。这个解决方案不会满足OP的所有标准,因为它会重新加载页面,唯一的方法是使用javascript来实现他的目标goal@LemuelBotha他说不要进入另一个页面,因为我们知道有一个page1.php page2.php page3.php,他还要求提供一个php解决方案,但感谢否决票,堆栈溢出变成了什么。。。
//this checks if the submit button or the name you've given in the submit button is set
if(isset($_POST['submit'])){

    //getting the html element name to the variable $name
    $name=$_POST['name'];

        //do your validation here
        if($name==''){// this checks if the $name field is null or empty
            // error alert user
        }else{
            // do your required tasks here or simply add an else if 
            // and check for another validation
        }
}