G
georgelaughalot
Guest
this is the code i have been using but something goes wrong somewhere and it fails no errors but it simply reloads the page and discards the information i put in
<strong>Update multiple rows in mysql</strong><br>
<?php
$host="xxx.xxx.xxx.xxx";
$username="HSR_CR";
$password="xxxxxxxxx";
$db_name="HSR_CR";
$tbl_name="COPE";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Scouts Name</strong></td>
<td align="center"><strong>Troop Number</strong></td>
<td align="center"><strong>Week</strong></td>
<td align="center"><strong>Completion</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $ID[]=$rows['ID']; ?><? echo $rows['ID']; ?></td>
<td align="center"><input name="ScoutName[]" type="text" id="ScoutName" value="<? echo $rows['ScoutName']; ?>"></td>
<td align="center"><input name="TroopNumber[]" type="text" id="TroopNumber" value="<? echo $rows['TroopNumber']; ?>"></td>
<td align="center"><input name="Week[]" type="text" id="Week" value="<? echo $rows['Week']; ?>"></td>
<td align="center"><input name="Completion[]" type="text" id="Completion" value="<? echo $rows['Completion']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center">
<input type="Submit" name="Submit" id="Submit" value="Submit">
</td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
if($Submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET Completion='$Completion[$i]' WHERE ID='$ID[$i]'";
$result1=mysql_query($sql);
}
}
if($result1){
header("location:index.php");
}
mysql_close();
?>
<strong>Update multiple rows in mysql</strong><br>
<?php
$host="xxx.xxx.xxx.xxx";
$username="HSR_CR";
$password="xxxxxxxxx";
$db_name="HSR_CR";
$tbl_name="COPE";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Scouts Name</strong></td>
<td align="center"><strong>Troop Number</strong></td>
<td align="center"><strong>Week</strong></td>
<td align="center"><strong>Completion</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $ID[]=$rows['ID']; ?><? echo $rows['ID']; ?></td>
<td align="center"><input name="ScoutName[]" type="text" id="ScoutName" value="<? echo $rows['ScoutName']; ?>"></td>
<td align="center"><input name="TroopNumber[]" type="text" id="TroopNumber" value="<? echo $rows['TroopNumber']; ?>"></td>
<td align="center"><input name="Week[]" type="text" id="Week" value="<? echo $rows['Week']; ?>"></td>
<td align="center"><input name="Completion[]" type="text" id="Completion" value="<? echo $rows['Completion']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center">
<input type="Submit" name="Submit" id="Submit" value="Submit">
</td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
if($Submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET Completion='$Completion[$i]' WHERE ID='$ID[$i]'";
$result1=mysql_query($sql);
}
}
if($result1){
header("location:index.php");
}
mysql_close();
?>