add.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>添加记录</title>
<script type="text/javascript">
function addrec()
{
    var rec = document.getElementById('rec');
    var nodeFather = rec.parentNode;
    var node_clone = rec.cloneNode();
    content = rec.innerHTML;
    node_clone.removeAttribute('id');
    node_clone.innerHTML = content;
    nodeFather.appendChild(node_clone);
}
function submitf(){
var fm = document.getElementById("fm");
fm.submit();
}
</script>
</head><body>
<form action="add.php" method="post" id="fm">
  <div id="rec">
    公告标题<input name="title[]">&nbsp;
    公告内容<input size="50" name="content[]">
  </div>
</form>
<input type="button" onClick="addrec()" value="增加"/>
<input type="button" value="保存" onClick="submitf()"/></body>
</html>add.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>保存</title>
</head><body>
<?php
if(isset($_POST['title'])){
$title = $_POST['title'];
$content = $_POST['content'];
$i = 0;
foreach($title as $v){

echo "公告标题:".$v." 公告内容".$content[$i]."<br/>";

$i++;
}

}
?>
<a href="add.html">继续添加</a>
</body>
</html>

解决方案 »

  1.   

    mysql_query("insert into table (表中字段)value(Form提交值)");
      

  2.   

    用表单提交到add.php中,在里面调增加的方法
      

  3.   

    你这个代码不全
    先要连接数据库
    mysql.connect(host,user,pwd,database)
    然后mysql_query(insert into table title,content) value(value1,value2);
      

  4.   

      function connect( $host, $user, $pwd, $db, $charset='utf8' ){
        // 连接数据库
       $db = mysqli_connect( $host, $user, $pwd, $db ) OR
              exit( mysqli_connect_error() );
       // 设置编码
       mysqli_set_charset( $db, $charset );
       return $db;
      }
     function add( $table , $data ){
        global $db;
        $sql = "insert into `$table` (`";
        $sql.= implode( '`,`', array_keys( $data ) );
        $sql.= "`) values('";
        $sql.= implode( "','", array_values( $data ) );
        $sql.="')";
        $res = mysqli_query( $db, $sql );
        return $res && mysqli_insert_id( $db );
      }
    希望可以帮到你
      

  5.   

    <?php //开启Session
       session_start();
        header("Content-type:text/html;charset=utf-8"); $link = mysqli_connect('localhost','root','123456','panda_work'); if (!$link) {
     die("连接失败:".mysqli_connect_error());
    }$workname = @$_POST['workname'];
    $rank = @$_POST['rank'];
    $category = @$_POST['category'];
    $deadline = @$_POST['deadline'];
    $description = @$_POST['description'];$username = @$_SESSION['username'];
    if($category==""||$rank==""||$category==""||$deadline==""||$description==""||$username=="")
    {
     echo "<script>alert('未接收——信息读取失败');window.location.href='../../html/form_validate.html'</script>";
     return;
    }$sql = "select * from panda_admin where name='{$username}'";
    $res = mysqli_query($link, $sql); if($row = mysqli_fetch_row($res))
     {        $id = $row[0]; }else{
      echo "<script>alert('未获得ID——信息读取失败');window.location.href='../../html/form_validate.html'</script>";
      return;
     }$addsql = "insert into panda_work(id,name,description, deadline,category,rank) 
    values('$id','$workname','$description','$deadline','$category','$rank')";if((mysqli_query($link,$addsql)))

    echo "<script>alert('插入成功!');window.location.href='../../html/form_validate.html'</script>";
    }
    else{

     echo "<script>alert('未插入成功——数据插入失败');</script>";
    }
    ?>
    这是我以前做的一个项目的片段,实现一个表单录入到数据库功能。