<?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());
    }
    ?> 这样,别把php和mysql弄混了
      

  2.   

    这个和楼上的都可以:<?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())";
    }
    ?> 
      

  3.   

    还有,数组的索引需要引号括住。(根据http://topic.csdn.net/u/20090208/17/38d220f6-bdf7-41b3-866c-03615cc9ab3f.html3楼的提醒)最终代码:
    <?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())";
    }
    ?>