php
代码,
但它无法在数据库中插入所有值
<?php
session_start();
require_once("include/config.php");
$num=$_POST['n'];
$i=0;
if( isset($_POST['submit']) )
{
$num=$_POST['n'];
echo "ji".$num;
for($i=0;$i<=$num; $i++)
{
$j=addslashes($_POST['t1'][$i]);
$m=addslashes($_POST['t2'][$i]);
$sql= "INSERT INTO ba (a,b)values('$j','$m');";
$res =mysqli_query($con,$sql) ;
$i++;
if($res)
{
echo "<script>alert('Family details submitted successfully');document.location.href='b.php';</script>";
}
else
{
echo "<script>alert('Error. Please Retry');document.location.href='b.php';</script>";
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form name="sdfs" method="post">
<table border="3">
<?php
while($i<$num)
{
echo "<tr><td><input type='text' id='t1[$i]' name='t1[$i]'></td><td>
<input type='text' id='t2[$i]' name='t2[$i]'></td>
";
$i++;
}
?>
<input type="submit" name="submit" id="submit" value="submit" />
</tr>
</form>
</body>
</html>
num的值是从另一页获得的.... 替换值插入db ...但我想将所有值插入到通过表单获取的数据库中 请找到解决这个问题的方法........................