本文介绍了将所有单元格更新到数据库各自的行如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<!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>
<?php
$con=mysqli_connect("localhost","root","","dbtest");
$name="";
$age="";
$address="";
$row="";
$n=$a=$ad="";
$i=1;
var_dump($_REQUEST);
?>
<?php
$ACTION="";
if(isset($_REQUEST['hidid']))
{
$hidid = $_REQUEST['hidid'];
$hidcount = count ($hidid);
echo "Total:".$hidcount;
for($j=1;$j<=$hidcount;$j++)
{
$name=$_REQUEST['name'.$j];
$age=$_REQUEST['age'.$j];
$address=$_REQUEST['add'.$j];
$upd="update tbl_grid set name='".$_REQUEST['name']."',age='".$_REQUEST['age']."',address='".$_REQUEST['add']."')";
$row=mysqli_query($con,$upd);
}
}
?>
<form name="grid" action="retrivegrid.php" method="post">
<table width="400" align="center" bgcolor="#66CCCC">
<tr>
<td>Name : </td>
<td>Age : </td>
<td>Address :
</td>
</tr>
<?php
$rtr="select * from tbl_grid";
$row=mysqli_query($con,$rtr);
while($rs=mysqli_fetch_array($row))
{ $ID=$rs['ID'];
$name=$rs['name'];
$age=$rs['age'];
$address=$rs['address'];
$i+=1;
?>
<tr>
<input type="hidden" name="hidid[]" id="hidid" value="<?php echo $i?>" />
<td><input type="text" name="name<?php echo $i?>" value="<?php echo $name; ?>"</td>
<td><input type="text" name="age<?php echo $i?>" value="<?php echo $age; ?>"</td>
<td><input type="text" name="address<?php echo $i?>" value="<?php echo $address; ?>"</td>
</tr>
<?php
//echo $name.$age.$address."<br>";
}?>
<tr>
<td colspan="3" align="center">
<input type="submit" name="update" value="Update" />
<input name="ACTION" type="hidden" id="ACTION" title="update" value="UPDATE" />
</td>
</tr>
</tr>
</table>
</form>
</body>
</html>
推荐答案
这篇关于将所有单元格更新到数据库各自的行如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!