这是表结构,我导出来的CREATE TABLE `employees` (
  `id` tinyint(4) NOT NULL auto_increment,
  `first` varchar(20) NOT NULL default '',
  `last` varchar(20) NOT NULL default '',
  `address` varchar(255) NOT NULL default '',
  `position` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `id` (`id`),
  UNIQUE KEY `id_2` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;-- 
-- 导出表中的数据 `employees`
-- INSERT INTO `employees` VALUES (1, 'Bob', 'Smith', '128 Here St, Cityname', 'Marketing Manager');
INSERT INTO `employees` VALUES (2, 'John', 'Roberts', '45 There St , \r\nTownville', 'Telephonist');
INSERT INTO `employees` VALUES (3, 'Brad', 'Johnson', '1/34 Nowhere Blvd, \r\nSnowston', 'Doorman');
INSERT INTO `employees` VALUES (4, 't', 'st', 'ss', 'ion');
INSERT INTO `employees` VALUES (5, '$first', '$last', '$address', '$position');

解决方案 »

  1.   

    改成这样试试看 $sql = "INSERT INTO employees (first,last,address,position)
    VALUES ('".$first."','".$last."','".$address."','".$position."')";
      

  2.   

    把: <form method="post" action="<?php echo $PATH_INFO?>">
    改成: <form method="post" action="<?php echo $PATH_INFO;?>">试试!
      

  3.   

    $sql = "INSERT INTO employees (first,last,address,position)
      VALUES ('$first','$last','$address','$position')";  echo $sql;//显示一下这条sql语句,你自然就知道哪里错了。  $result = mysql_query($sql);
      

  4.   

    感谢各位的回复,但是还是不行,不知哪有问题,我初学PHP
      

  5.   

    mysql_query的时候把句柄加上去吧 $db = mysql_connect("localhost", "root","overmax");  mysql_select_db("mydb",$db);  $sql = "INSERT INTO employees (first,last,address,position)
      VALUES ('$first','$last','$address','$position')";
      $result = mysql_query($sql,$db);
                ~~~~~~~~~~~~~~~~~~~~~~~
      

  6.   

    ...........................
    为什么大家都把思路集中在数据库的连接上面呢,上面的程序很虽然,少了接收数据部分嘛,
    请问没定义过$submit并且没给$submit赋值,if($submit)这一句能通过吗?
    在文件上头加上下面这几句试试
    <?php 
    $submit=null;
    if ( isset($_POST["submit"])){
    $submit=$_POST['submit'];
    }
    然后在if($submit){
    下面加$first=$_POST['first'];
    $last=$_POST['last'];
    $address=$_POST['address'];
    $position=$_POST['position'];
      

  7.   

    <?php
      $db = mysql_connect("localhost", "root","overmax");  mysql_select_db("mydb",$db);
      
    $sql = "INSERT INTO employees (first,last,address,position)
      VALUES ('$first','$last','$address','$position')";  echo $sql;//显示一下这条sql语句,你自然就知道哪里错了。  $result = mysql_query($sql);  
      ?>但我用这个代码,刷新一次网页,就会往有格加入一条记录!  不知哪错了
      

  8.   

    <?php
    if ($submit) {
    $db = mysql_connect("localhost", "root","pass");
    mysql_select_db("mydb",$db);
    $sql = "INSERT INTO employees (first,last,address,position)
    VALUES ('$first','$last','$address','$position')";
    $result = mysql_query($sql);
    echo "Thank you! Information entered.&nbsp;&nbsp;<a href='javascript:history.back()'>Back</a>\n";
    /*while (list($name, $value) = each($HTTP_POST_VARS)) {
      echo "$name = $value<br>\n";}*/
    } else{
    ?>
    <form method="post" action="<?php echo $PATH_INFO?>">
    &nbsp;&nbsp;名:<input type="Text" name="first"><br>
    &nbsp;&nbsp;姓:<input type="Text" name="last"><br>
    住址:<input type="Text" name="address"><br>
    职位:<input type="Text" name="position"><br>
    <input type="Submit" name="submit" value="输入信息">
    </form>
    <? }?>
    這段代碼沒問題呀再建一個數據庫看一下了。。
      

  9.   

    完整的,自己试试吧,最后再说一次,绝对不是数据库或连接的问题.下面段以经做过实验了,可以。表是用你上面提供的语句建的,
    <html><body><?php
    $submit=null;
    if ( isset($_POST["submit"])){
    $submit=$_POST['submit'];
    }if ($submit) {
    $first=$_POST['first'];
    $last=$_POST['last'];
    $address=$_POST['address'];
    $position=$_POST['position'];
      
      // 处理表格输入  $db = mysql_connect("localhost", "root","overmax");  mysql_select_db("mydb",$db);  $sql = "INSERT INTO employees (first,last,address,position)
      VALUES ('$first','$last','$address','$position')";
      $result = mysql_query($sql);  echo "Thank you! Information entered.\n";} else
    { // 显示表格内容  ?>  <form method="post" action="<?php echo $PATH_INFO;?>">
      
      名:<input type="Text" name="first"><br>
      
      姓:<input type="Text" name="last"><br>
      
      住址:<input type="Text" name="address"><br>  职位:<input type="Text" name="position"><br>  <input type="Submit" name="submit" value="输入信息">  </form>  <?php} // end if,if结束
    ?></body></html>
       您现在已经向数据库中插入数据了。不过还有很多完善的工作要
      

  10.   

    朋友,请关注一下此帖:
    http://community.csdn.net/Expert/topic/4338/4338855.xml?temp=.8305628