本帖最后由 u012296415 于 2013-11-26 11:04:16 编辑

解决方案 »

  1.   

    insert.php的代码是这样的
     <?php
     error_reporting(E_ALL ^E_DEPRECATED);
     $con = mysql_connect("localhost:/tmp/mysql.sock","chris","6661573");
     if (!$con)
         echo "shibai";
       else echo "connect mysql success";
     mysql_select_db("birth", $con);
     $sql="insert shengri (name,sex,birth) values ('$_POST[name]','$_POST[sex] ','$_POST[birth]')";
     if (!mysql_query($sql,$con))
       {
       die('Error: ' . mysql_error());
       }
     echo "1 record added";
     mysql_close($con)
     ?>
     求大神们给看看 
      

  2.   

    把你前台的页面换成下面的
    <html>
     <head>
     </br>
     you can add a data into this table
     </br>
     <script type="text/javascript">
     function loadXMLDoc ()
     {
     var xmlhttp;
     var name = document.getElementById("name").value;
     var sex = document.getElementById("sex").value;
     var birth = document.getElementById("birth").value; xmlhttp=new XMLHttpRequest ();
     xmlhttp.onreadystatechange = function()
     {
    if (xmlhttp.readyState == 4 && xmlhttp.responseText)
    {
    alert(xmlhttp.responseText);
    }
     }
     xmlhttp.open("POST","./insert.php",true);
     xmlhttp.setRequestHeader('content-type','application/x-www-form-urlencoded');
     xmlhttp.send("name="+name+"&sex="+sex+"&birth="+birth);
     }
     </script>
     </head>
     <body>
     name: <input type="text" name="name" id="name" />
     sex: <input type="text" name="sex" id="sex"/>
     birth: <input type="date" name="birth" id="birth"/>
     <button type="button" onclick="loadXMLDoc ()">submit </button>
     </body>
     </html>