<?php
function _get($str){
$val = !empty($_GET[$str]) ? $_GET[$str] : null;
return $val;
}
include("conn.php");
if (_get('submit')){
$sql="insert into message(id,user,title,content,lastdate)"."values
('','_get(user)','_get(title)','_get(content)',now())";
mysql_query($sql);
echo "发布成功";
}
?>
<form action="add.php" method="post">
用户:
<input type="text" size="10" name="user"/><br>
标题:
<input type="text" name="title"/><br/>
内容:
<textarea name="content"></textarea><br/>
<input type="submit" name="submit" value="发布留言"/>
</form> 麻烦帮我看看出了什么问题啊......就是插不进数据啊,也不会报错,就是感觉每次都没有执行if下的sql语句啊,每次都点了提交按钮啊,怎么会条件判断不成立呢

解决方案 »

  1.   

    你用POST发送表单,却用$_GET来接受参数,所以没有$var为null,所以if条件不成立,所以不执行SQL语句
      

  2.   

    POST传递表单内容  接收当然也得一样用POST
      

  3.   

    在form表单中的method选择用post时,后台的php接收处理的地方需要用$_POST来接收;若使用get时就可以用你写的这个_get方法。在后台用$_REQUEST可以同时接收get和post两种方式提交过来的参数,不过个人不建议这么使用
      

  4.   

    <form action="add.php" method="post">
    你提交表单使用POST方法$val = !empty($_GET[$str]) ? $_GET[$str] : null;
    而接受参数适用GET方法,当然获取不到。改为:$val = !empty($_POST[$str]) ? $_POST[$str] : null;
      

  5.   

     <form action="add.php" method="post">
    form表单提交方式是postfunction _get($str){
    $val = !empty($_GET[$str]) ? $_GET[$str] : null;
    return $val;
    }
    为什么获取的时候使用$_GET