Lindsie 0 Newbie Poster

I am a newbie so please be kind. I have put together a form using multiple queries which pulls information from MySQL tables that are joined by ID number. It displays the info in a form so updates can be made. I cannot get it to update more than one of the records at a time.

For example: Joe Blow lives at 123 sesame street and has 3 children: Sally F 10, Bobby M 8 & Jake M 4 - the child info is stored in a separate table and pulled with a separate query. I make changes to each of the records pertaining to the children but it only saves the changes made to the last record. What am I doing wrong? How would I go about making it so a new child record could be added if necessary?

Part of the code that pulls multiple records...

<? $sql = "SELECT * FROM $usertable2 where $ = $id";

$result = mysql_query($sql);

if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();

if (mysql_num_rows($result) == 0) {
    echo "No children listed.";

while ($row = mysql_fetch_assoc($result)) {?>
          <td width="24%"><input type="text" size="40" name="ChildFName[i]"  value="<? echo $row["ChildFName"] ?>"/></td>
          <td width="23%"><input type="text" size="40" name="ChildLName" value="<? echo $row["ChildLName"]  ?>"/></td>
          <td width="13%">
            <input type="text" size="20" name="ChildDOB" value="<? echo $row["ChildDOB"] ?>"/></td>
          <td width="4%">
            <input type="text" size="3" name="Age" value="<? echo $row["Age"] ?>"/></td>
          <td width="14%"><input type="text" size="3" name="ChildGender" value="<? echo $row["ChildGender"] ?>"/></td>
          <td width="19%">
            <input type="text" size="3" name="ShowedID" value="<? echo $row["ShowedID"]?>"/>
            <input type="hidden" size="3" name="childID" value="<? echo $row["childID"]?>"/>
            <input type="hidden" size="3" name="id" value="<? echo $row["id"]?>"/></td>

what i have for the processing code for this part...

$ChildFName = $_POST['ChildFName'];
$ChildLName = $_POST['ChildLName'];
$ChildDOB = $_POST['ChildDOB'];
$ChildGender = $_POST['ChildGender'];
$Age = $_POST['Age'];
$ShowedId = $_POST['ShowedId'];
$childID = $_POST['childID'];
$id = $_POST['id'];

$query="UPDATE $usertable2 SET ChildFName='".$ChildFName."',ChildLName='".$ChildLName."' WHERE childID='".$childID."'";
   $result = mysql_query($query) or die('Sorry, we are unable to process your request.' . mysql_error());
   if ($result)
      echo "<br><br><h1><center>Database has been updated!</h1><br><br><h2>\n";

Any help is much appreciated!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.