Hi there. I have a page that lists the records of a table. On this page I want to be able to edit/update two attributes of these records by using checkboxes - e.g., being able to update multiple records at once. I thought the smartest way to achieve this would be by using arrays.
Currently I can get the name attribute to update, if both the height and name checkbox are ticked. I cannot get the height attribute to update at all.
<?php
include("connection.php");
$conn = oci_connect($UName,$PWord,$DB) or die("Error");
if (empty($_POST["check1"]))
{
$query = "SELECT * FROM HORSE ORDER BY HORSE_NAME";
$stmt = oci_parse($conn,$query);
oci_execute($stmt);
$Horses = oci_fetch_array ($stmt);
?>
<?php
while ($Horses = oci_fetch_array ($stmt))
{
?>
<tr>
<td><?php echo $Horses["HORSE_ID"]; ?></td>
<td><input type="checkbox" name="check1[]" value="<?php echo $Horses["HORSE_ID"]; ?>"><input type="text" size="5" name="<?php echo $Horses["HORSE_ID"]; ?>" value="<?php echo $Horses["HORSE_HEIGHT"]; ?>"></td>
<td><input type="checkbox" name="check2[]" value="<?php echo $Horses["HORSE_ID"]; ?>"><input type="text" size="20" name="<?php echo $Horses["HORSE_ID"]; ?>" value="<?php echo $Horses["HORSE_NAME"]; ?>"></td>
</tr>
<?php
}
?>
</table><p />
<h4><input type="submit" value="Update Selected Horses"></h4>
</form>
<?php
oci_free_statement($stmt);
}
else
{
foreach($_POST['check1'] as $horse_id)
{
$query = "UPDATE HORSE SET HORSE_HEIGHT = ".$_POST[$horse_id]." WHERE HORSE_ID ='".$horse_id."'";
$stmt = oci_parse($conn,$query);
oci_execute($stmt);
}
foreach($_POST['check2'] as $horse_name)
{
$query = "UPDATE HORSE SET HORSE_NAME = '$_POST[$horse_name]' WHERE HORSE_ID =''.$horse_name.''";
$stmt = oci_parse($conn,$query);
oci_execute($stmt);
}
}
?>