<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  mysql_query("set names utf8");
mysql_select_db("test", $con);
foreach($_POST["category"] as $k=>$v){ 
    $category = $v; 
    $client = $_POST["client"][$k];
    $total = $_POST["total"][$k]; 
    $price = $_POST["price"][$k];
    $sql = "insert into test values('','$category','$client','$total','$price')";
mysql_query($sql);
    }
echo "ok";//*/
mysql_close($con); //为什么一定要在跳转之后刷新才能insert数据???
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
*{
margin: 0px;
padding:0px;
}
#data,th,tr,td {
margin: 10px auto auto 10px;
border-collapse: collapse;
border: 1px solid #000000;
}
input{
text-align: center;
border: 0 none #FFFFFF;
}
#submit{
border: 1px solid #000000;
margin: 5px auto auto 50px;
}
</style>
</head>
<body>
<form action="connect.php" method="post" id="mydata">
<table id="data" border="0">
<tr>
<th>种类</th>
<th>客户</th>
<th>数量</th>
<th>价格</th>
</tr>
<tr>
<td><input type="text" id="category" name="category[]" value="鸡蛋"></td>
<td><input type="text" id="client" name="client[]" value="家乐福"></td>
<td><input type="text" id="total" name="total[]" value="450公斤"></td>
<td><input type="text" id="price" name="price[]" value="6.00"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="苹果"></td>
<td><input type="text" id="client" name="client[]" value="沃尔玛"></td>
<td><input type="text" id="total" name="total[]" value="500公斤"></td>
<td><input type="text" id="price" name="price[]" value="3.5"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="苹果"></td>
<td><input type="text" id="client" name="client[]" value="家乐福"></td>
<td><input type="text" id="total" name="total[]" value="300公斤"></td>
<td><input type="text" id="price" name="price[]" value="3.4"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="鸭梨"></td>
<td><input type="text" id="client" name="client[]" value="沃尔玛"></td>
<td><input type="text" id="total" name="total[]" value="500公斤"></td>
<td><input type="text" id="price" name="price[]" value="3.8"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="柑桔"></td>
<td><input type="text" id="client" name="client[]" value="沃尔玛"></td>
<td><input type="text" id="total" name="total[]" value="5000公斤"></td>
<td><input type="text" id="price" name="price[]" value="1.5"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="鸡蛋"></td>
<td><input type="text" id="client" name="client[]" value="家乐福"></td>
<td><input type="text" id="total" name="total[]" value="450公斤"></td>
<td><input type="text" id="price" name="price[]" value="6.00"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="苹果"></td>
<td><input type="text" id="client" name="client[]" value="沃尔玛"></td>
<td><input type="text" id="total" name="total[]" value="500公斤"></td>
<td><input type="text" id="price" name="price[]" value="3.5"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="苹果"></td>
<td><input type="text" id="client" name="client[]" value="家乐福"></td>
<td><input type="text" id="total" name="total[]" value="300公斤"></td>
<td><input type="text" id="price" name="price[]" value="3.4"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="鸭梨"></td>
<td><input type="text" id="client" name="client[]" value="沃尔玛"></td>
<td><input type="text" id="total" name="total[]" value="500公斤"></td>
<td><input type="text" id="price" name="price[]" value="3.8"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="柑桔"></td>
<td><input type="text" id="client" name="client[]" value="沃尔玛"></td>
<td><input type="text" id="total" name="total[]" value="5000公斤"></td>
<td><input type="text" id="price" name="price[]" value="1.5"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="鸡蛋"></td>
<td><input type="text" id="client" name="client[]" value="家乐福"></td>
<td><input type="text" id="total" name="total[]" value="450公斤"></td>
<td><input type="text" id="price" name="price[]" value="6.00"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="苹果"></td>
<td><input type="text" id="client" name="client[]" value="沃尔玛"></td>
<td><input type="text" id="total" name="total[]" value="500公斤"></td>
<td><input type="text" id="price" name="price[]" value="3.5"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="苹果"></td>
<td><input type="text" id="client" name="client[]" value="家乐福"></td>
<td><input type="text" id="total" name="total[]" value="300公斤"></td>
<td><input type="text" id="price" name="price[]" value="3.4"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="鸭梨"></td>
<td><input type="text" id="client" name="client[]" value="沃尔玛"></td>
<td><input type="text" id="total" name="total[]" value="500公斤"></td>
<td><input type="text" id="price" name="price[]" value="3.8"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="柑桔"></td>
<td><input type="text" id="client" name="client[]" value="沃尔玛"></td>
<td><input type="text" id="total" name="total[]" value="5000公斤"></td>
<td><input type="text" id="price" name="price[]" value="1.5"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="鸡蛋"></td>
<td><input type="text" id="client" name="client[]" value="家乐福"></td>
<td><input type="text" id="total" name="total[]" value="450公斤"></td>
<td><input type="text" id="price" name="price[]" value="6.00"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="苹果"></td>
<td><input type="text" id="client" name="client[]" value="沃尔玛"></td>
<td><input type="text" id="total" name="total[]" value="500公斤"></td>
<td><input type="text" id="price" name="price[]" value="3.5"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="苹果"></td>
<td><input type="text" id="client" name="client[]" value="家乐福"></td>
<td><input type="text" id="total" name="total[]" value="300公斤"></td>
<td><input type="text" id="price" name="price[]" value="3.4"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="鸭梨"></td>
<td><input type="text" id="client" name="client[]" value="沃尔玛"></td>
<td><input type="text" id="total" name="total[]" value="500公斤"></td>
<td><input type="text" id="price" name="price[]" value="3.8"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="柑桔"></td>
<td><input type="text" id="client" name="client[]" value="沃尔玛"></td>
<td><input type="text" id="total" name="total[]" value="5000公斤"></td>
<td><input type="text" id="price" name="price[]" value="1.5"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="鸡蛋"></td>
<td><input type="text" id="client" name="client[]" value="家乐福"></td>
<td><input type="text" id="total" name="total[]" value="450公斤"></td>
<td><input type="text" id="price" name="price[]" value="6.00"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="苹果"></td>
<td><input type="text" id="client" name="client[]" value="沃尔玛"></td>
<td><input type="text" id="total" name="total[]" value="500公斤"></td>
<td><input type="text" id="price" name="price[]" value="3.5"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="苹果"></td>
<td><input type="text" id="client" name="client[]" value="家乐福"></td>
<td><input type="text" id="total" name="total[]" value="300公斤"></td>
<td><input type="text" id="price" name="price[]" value="3.4"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="鸭梨"></td>
<td><input type="text" id="client" name="client[]" value="沃尔玛"></td>
<td><input type="text" id="total" name="total[]" value="500公斤"></td>
<td><input type="text" id="price" name="price[]" value="3.8"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="柑桔"></td>
<td><input type="text" id="client" name="client[]" value="沃尔玛"></td>
<td><input type="text" id="total" name="total[]" value="5000公斤"></td>
<td><input type="text" id="price" name="price[]" value="1.5"></td>
  </tr>
<tr>
<td><input type="text" id="category" name="category[]" value="鸡蛋"></td>
<td><input type="text" id="client" name="client[]" value="家乐福"></td>
<td><input type="text" id="total" name="total[]" value="450公斤"></td>
<td><input type="text" id="price" name="price[]" value="6.00"></td>
  </tr>
</table>
<input type="submit" id="submit" value="保存内容"/>
</form>
</body>
</html>

解决方案 »

  1.   

    就是点击了submit 之后跳到的页面,在这个页面一定要刷新,数据库里才能看到数据.
      

  2.   

    有点不明白流程是 
    1提交
    2->php插入数据库(没操作)
    3->刷新(相当于重复提交)才能插入?进行第2步时,你用什么查看数据库发现没有插入的?
      

  3.   

    知道了,原来是在phpmyadmin里没有刷新数据库.现在可以了,谢谢你.