Both of your form fields have the same name ($row["HORSE_ID"]) which will cause problems!
Nev Stokes
2010-09-12 13:00:00
Both of your form fields have the same name ($row["HORSE_ID"]) which will cause problems!
Well, you set name
and height
both to $_POST[$horse_id]
in your query:
$query = "UPDATE horse set horse_name = ".$_POST[$horse_id]."horse_height = ".$_POST[$horse_id]." WHERE horse_id = '".$horse_id."'";
And you even give the input elements the same name:
name="<?php echo $row["HORSE_ID"]; ?>"
The name of an input element becomes the key of the $_POST
array on the PHP side. So give the input fields the right names, e.g.:
<input type="text" size="24"
name="horse_name[<?php echo $row["HORSE_ID"]; ?>]"
value="<?php echo $row["HORSE_NAME"]; ?>">
<input type="text" size="5"
name="horse_height[<?php echo $row["HORSE_ID"]; ?>]"
value="<?php echo $row["HORSE_HEIGHT"]; ?>">
and change your query to
"UPDATE horse set horse_name = ".mysql_real_escape($_POST['horse_name'][$horse_id])
."horse_height = ".mysql_real_escape($_POST['horse_name'][$horse_id])
." WHERE horse_id = '".$horse_id."'"
<input type="text" size="24"
name="HorseName"
id="name-<?=row["HORSE_ID"] ?>"
value="<?php echo $row["HORSE_NAME"]; ?>"></td>
<td align="center">
<input type="text" size="5"
name="HorseHeight"
id="height-<?=row["HORSE_ID"] ?>"
value="<?php echo $row["HORSE_HEIGHT"]; ?>"></td>
<td align="center">
This way, you can still use the id to make the checkboxes for the particular horse unique
UPDATE:
Go ahead and do it like this for each horse:
<input type="text" size="24" name="HorseName" value="<?= $row["HORSE_NAME"] ?>" />
<input type="text" size="5" name="HorseHeight"value="<?= $row["HORSE_HEIGHT"]; ?>" />
<input type="hidden" name="HORSE_ID" value="<?= $row["HORSE_ID"] ?>" />
Then your php and query can look like this:
$HORSE_NAME = $_POST['HORSE_NAME'];
$HORSE_HEIGHT = $_POST['HORSE_HEIGHT'];
$HORSE_ID = $_POST['HORSE_ID'];
"UPDATE table_name SET HORSE_NAME = $HORSE_NAME, HORSE_HEIGHT=$HORSE_HEIGHT WHERE HORSE_ID = $HORSE_ID"