新人啊关于表单的

WBOY
Release: 2016-06-13 12:10:47
Original
1061 people have browsed it

新人求助啊!关于表单的
我做了个简单的留言板,只写了一小部分,可是规则写了,比如我不输标题,在前台还是无法显示错误,求帮助
------------------------------------------这是留言板模板:
nbsp;html>






    

留言板

   
    
" method="post" style="border:1px solid #ddd; width:500px; margin-left:370px">
        

        姓名:
        
        
        

        标题:
        
        
        

        
    



------------------------------------------这是验证部分:
//留言板验证规则
if($_SERVER["REQUEST_METHOD"] == "POST"){

if(empty($_POST["name"])){
$nameError = "用户名不能为空";
}else{
    $name = test_input($_POST["name"]);
}

    if(empty($_POST["title"])){
     $titleError = "标题不能为空";
    }else{
        $title = test_input($_POST["title"]);
    }

if(empty($_POST["content"])){
$contentError = "评论内容不能为空";
}else{
    $content = test_input($_POST["content"]);
}

}


//去除空格及反斜线方法
function test_input($data){
$data = trim($data);
$data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
------解决思路----------------------
nbsp;html>






$nameError = $titleError= $contentError = "";?>

//留言板验证规则
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(empty($_POST["name"])){
$nameError = "用户名不能为空";
}else{
$name = test_input($_POST["name"]);
}

    if(empty($_POST["title"])){
     $titleError = "标题不能为空";
    }else{
        $title = test_input($_POST["title"]);
    }
if(empty($_POST["content"])){
 $contentError = "评论内容不能为空";
}else{ 
$content = test_input($_POST["content"]);
}
}


//去除空格及反斜线方法
function test_input($data){
$data = trim($data);
$data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

?>
    

留言板

   
    
" method="post" style="border:1px solid #ddd; width:500px; margin-left:370px">
        

        姓名:
        
        
        

        标题:
        
        
        

        
    



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!