 |
|
ลองดูแบบนี้ครับ
<?php
if (isset($_POST['test'])){
mysql_connect('localhost','root','root_password');
$n=1;
//ขณะที่ field แรกของ record ที่ $n ยังมีข้อมูลอยู่
//ให้เพิ่ม ข้อมูลของ $_POST[data][$n] ลงในตาราง
while(!empty($_POST['data'][$n]['f1'])){
$record = array_map('mysql_real_escape_string',$_POST['data'][$n]);
$s = "'".implode("','",$record)."'";
$query = "INSERT INTO tb1(f1,f2,f3,f4,f5) VALUES($s)";
$res = mysql_query($query);
if (!$res){
echo "\n<br />".mysql_error();
}
$n++;
}
}else{
echo 'nodata';
}
?>
<form method="post" action="?">
<?php foreach(array(1,2,3,4,5) as $n): ?>
R <?php echo $n; ?>
<input type="text" name="data[<?php echo$n;?>][f1]" value="" />
<input type="text" name="data[<?php echo$n;?>][f2]" value="" />
<input type="text" name="data[<?php echo$n;?>][f3]" value="" />
<input type="text" name="data[<?php echo$n;?>][f4]" value="" />
<input type="text" name="data[<?php echo$n;?>][f5]" value="" />
<br />
<?php endforeach; ?>
<input type="submit" name="test" value="submit" />
</form>
|
 |
 |
 |
 |
Date :
2009-05-11 14:20:12 |
By :
num |
|
 |
 |
 |
 |
|
|
 |