<?php
include("common.php");
if($_POST["submit"])
{
echo $sql="insert into message (id,username,title,password,sex,content,lastdate) values ('', '$_POST[username]','$_POST[title]','$_POST[password]','$_POST[sex]','$_POST[content]',now())";
}
?>

解决方案 »

  1.   

    这个和楼上的都可以:<?php
    include("common.php");
    if($_POST["submit"])
    {
    echo $sql="insert into message (id,username,title,password,sex,content,lastdate) values (\"\",\"{$_POST[username]}\",\"{$_POST[title]}\",\"{$_POST[password]}\",\"{$_POST[sex]}\",\"{$_POST[content]}\",now())";
    }
    ?> 
      

  2.   

    您的错误在于:在SQL语句中$_POST[XXX]应该写成$_POST['XXX'],但是考虑到外层引号的影响以及书写的可读性。您最好在SQL语句的外层创建对应的变量,把$_POST['XXX']赋给变量,然后在SQL语句中用这些变量来书写,这样绝对不会有任何问题,而且程序的可读性也提高很多。
    所以上面的SQL语句写成:
    <?php 
    include("common.php");$username = $_POST['username'];
    $title = $_POST['title'];
    $password = $_POST['password'];
    $sex = $_POST['sex'];
    $content = $_POST['content'];
    $lastdate = now();
    //id一般是自增的,不用显式指定
    if($_POST["submit"]) 
    {
    echo $sql=insert into message (username,title,password,sex,content,lastdate) values ("$username","$title","$password","$sex","content","$lastdate"); 

    ?> 
      

  3.   

    $sql = "SELECT * FROM `table` WHERE `id`='{$_POST['id']}'";
      

  4.   


    echo $sql="" //后面要加到引号里