I'm trying to put together a registration form for little league baseball. I'd like to have a form where the parents can enter their information and the information for up to 5 children. I need a separate record for each player instead to one record for each family.

So what I need is to have the parent's information and one player's information in each record. If the parent is registering only one player, I'd like to only have one record created and not have four additional blank records.

Here is a very basic start to my registration form. If anyone knows of a solution for this, I'd be very grateful!

<form id="form1" name="form1" method="POST" action="insert.php">
<input type="text" name="ParentName" id="ParentName" />
<input type="text" name="Child1" id="Child1" />
<select name="Child1League" id="Child1League">
    <option value="1">Shetlan</option>
    <option value="2">Farm</option>
    <option value="3">Mustang</option>
    <option value="4">Bronco</option>
  </select>
<select name="Child2League" id="Child2League">
    <option value="1">Shetlan</option>
    <option value="2">Farm</option>
    <option value="3">Mustang</option>
    <option value="4">Bronco</option>
  </select>
<input type="text" name="Child2" id="Child2" />
<input type="submit" name="Submit" id="Submit" value="Submit" />
</form>

create a parents table. when a new parent signs up add their information into that table. then add a foreign key column 'parent_id' into a children table. this way, you won't have repeated records, meaning if a parent need to change something, the application won't have to update a row for every child they have, just one.

Thanks kkeith29. However, can you do all of this within one form or would you have to create two forms and have the parents register first and then the kids register second? I'd prefer to only have one form if possible.

ok. how is your form setup right now. After I have a rough idea of exactly how you want it, I will see what I can do. Can you also post your code?

Here is a copy of the entire form:

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO registration (ParentName, HomePhone, WorkPhone, Address, City, `State`, ZipCode, Email1, Email2, PlayerFirstName, PlayerLastName, YearsPLayed, PlayerSchool, PlayerDOB, League) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['ParentName'], "text"),
                       GetSQLValueString($_POST['HomePhone'], "text"),
                       GetSQLValueString($_POST['WorkPhone'], "text"),
                       GetSQLValueString($_POST['Address'], "text"),
                       GetSQLValueString($_POST['City'], "text"),
                       GetSQLValueString($_POST['State'], "text"),
                       GetSQLValueString($_POST['ZipCode'], "text"),
                       GetSQLValueString($_POST['Email1'], "text"),
                       GetSQLValueString($_POST['Email2'], "text"),
                       GetSQLValueString($_POST['PlayerFirstName'], "text"),
                       GetSQLValueString($_POST['PlayerLastName'], "text"),
                       GetSQLValueString($_POST['YearsPlayed'], "text"),
                       GetSQLValueString($_POST['PlayerSchool'], "text"),
                       GetSQLValueString($_POST['PlayerDOB'], "text"),
                       GetSQLValueString($_POST['League'], "text"));

  mysql_select_db($database_LBSB, $LBSB);
  $Result1 = mysql_query($insertSQL, $LBSB) or die(mysql_error());

  $insertGoTo = "registration.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!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>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
Parents Information:
  <table width="700" border="0" cellspacing="4" cellpadding="0">
    <tr>
      <td>Name</td>
      <td><input type="text" name="ParentName" id="ParentName" /></td>
      <td>Home Phone</td>
      <td><input name="HomePhone" type="text" id="HomePhone" size="15" maxlength="15" /></td>
      <td>Work Phone</td>
      <td><input name="WorkPhone" type="text" id="WorkPhone" size="15" maxlength="18" /></td>
    </tr>
    <tr>
      <td>Address</td>
      <td colspan="5"><input name="Address" type="text" id="Address" size="60" /></td>
    </tr>
    <tr>
      <td>City</td>
      <td><input name="City" type="text" id="City"/></td>
      <td>State</td>
      <td><input name="State" type="text" id="State" size="2"/></td>
      <td>Zip Code</td>
      <td><input name="ZipCode" type="text" id="ZipCode" size="11" /></td>
    </tr>
    <tr>
      <td>Email 1</td>
      <td><input type="text" name="Email1"/></td>
      <td>Email 2</td>
      <td><input type="text" name="Email2"/></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <br />
Player 1 Information:
<table width="700" border="0" cellspacing="4" cellpadding="0">
  <tr>
    <td>First Name</td>
    <td><input name="PlayerFirstName" type="text" id="PlayerFirstName"/></td>
    <td>Last Name</td>
    <td><input name="PlayerLastName" type="text" id="PlayerLastName"/></td>
    <td>DOB</td>
    <td><input name="PlayerDOB" type="text" id="PlayerDOB" size="11" /></td>
  </tr>
  <tr>
    <td>Experience</td>
    <td><input name="YearsPlayed" type="text" id="YearsPlayed" size="2" /></td>
    <td>School</td>
    <td><input name="PlayerSchool" type="text" id="PlayerSchool" /></td>
    <td>League</td>
    <td><label>
      <select name="League" id="League">
        <option value="1">Shetland</option>
        <option value="2">Farm</option>
        <option value="3">Mustang</option>
        <option value="4">Bronco</option>
        <option value="5">Pony</option>
      </select>
    </label></td>
  </tr>
</table>
<br />
Player 2 Information:
<table width="700" border="0" cellspacing="4" cellpadding="0">
  <tr>
    <td>First Name</td>
    <td><input name="PlayerFirstName2" type="text" id="PlayerFirstName2"/></td>
    <td>Last Name</td>
    <td><input name="PlayerLastName2" type="text" id="PlayerLastName2"/></td>
    <td>DOB</td>
    <td><input name="PlayerDOB2" type="text" id="PlayerDOB2" size="11" /></td>
  </tr>
  <tr>
    <td>Experience</td>
    <td><input name="YearsPlayed2" type="text" id="YearsPlayed2" size="2" /></td>
    <td>School</td>
    <td><input name="PlayerSchool2" type="text" id="PlayerSchool2" /></td>
    <td>League</td>
    <td><label>
      <select name="League2" id="League2">
        <option value="1">Shetland</option>
        <option value="2">Farm</option>
        <option value="3">Mustang</option>
        <option value="4">Bronco</option>
        <option value="5">Pony</option>
      </select>
    </label></td>
  </tr>
</table>
<br />
Player 3 Information:
<table width="700" border="0" cellspacing="4" cellpadding="0">
  <tr>
    <td>First Name</td>
    <td><input name="PlayerFirstName3" type="text" id="PlayerFirstName3"/></td>
    <td>Last Name</td>
    <td><input name="PlayerLastName3" type="text" id="PlayerLastName3"/></td>
    <td>DOB</td>
    <td><input name="PlayerDOB3" type="text" id="PlayerDOB3" size="11" /></td>
  </tr>
  <tr>
    <td>Experience</td>
    <td><input name="YearsPlayed3" type="text" id="YearsPlayed3" size="2" /></td>
    <td>School</td>
    <td><input name="PlayerSchool3" type="text" id="PlayerSchool3" /></td>
    <td>League</td>
    <td><label>
      <select name="League3" id="League3">
        <option value="1">Shetland</option>
        <option value="2">Farm</option>
        <option value="3">Mustang</option>
        <option value="4">Bronco</option>
        <option value="5">Pony</option>
      </select>
    </label></td>
  </tr>
</table>
<br />
Player 4 Information:
<table width="700" border="0" cellspacing="4" cellpadding="0">
  <tr>
    <td>First Name</td>
    <td><input name="PlayerFirstName4" type="text" id="PlayerFirstName4"/></td>
    <td>Last Name</td>
    <td><input name="PlayerLastName4" type="text" id="PlayerLastName4"/></td>
    <td>DOB</td>
    <td><input name="PlayerDOB4" type="text" id="PlayerDOB4" size="11" /></td>
  </tr>
  <tr>
    <td>Experience</td>
    <td><input name="YearsPlayed4" type="text" id="YearsPlayed4" size="2" /></td>
    <td>School</td>
    <td><input name="PlayerSchool4" type="text" id="PlayerSchool4" /></td>
    <td>League</td>
    <td><label>
      <select name="League4" id="League4">
        <option value="1">Shetland</option>
        <option value="2">Farm</option>
        <option value="3">Mustang</option>
        <option value="4">Bronco</option>
        <option value="5">Pony</option>
      </select>
    </label></td>
  </tr>
</table>
<br />
Player 5 Information:
<table width="700" border="0" cellspacing="4" cellpadding="0">
  <tr>
    <td>First Name</td>
    <td><input name="PlayerFirstName5" type="text" id="PlayerFirstName5"/></td>
    <td>Last Name</td>
    <td><input name="PlayerLastName5" type="text" id="PlayerLastName5"/></td>
    <td>DOB</td>
    <td><input name="PlayerDOB5" type="text" id="PlayerDOB5" size="11" /></td>
  </tr>
  <tr>
    <td>Experience</td>
    <td><input name="YearsPlayed5" type="text" id="YearsPlayed5" size="2" /></td>
    <td>School</td>
    <td><input name="PlayerSchool5" type="text" id="PlayerSchool5" /></td>
    <td>League</td>
    <td><label>
      <select name="League5" id="League5">
        <option value="1">Shetland</option>
        <option value="2">Farm</option>
        <option value="3">Mustang</option>
        <option value="4">Bronco</option>
        <option value="5">Pony</option>
      </select>
    </label></td>
  </tr>
</table>
<br />
<br />
<label>
  <input type="submit" name="Submit" id="Submit" value="Submit Registration" />
</label>
<input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>
Be a part of the DaniWeb community

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