HI,
I have the mysql insert code below and it never does what it is intend to be. Amazingly it does not show any error or warings. What's wrong with this code? Please help me this one as soon as you can.
<?php
require("config.php");
// Generate Dynamic Forms
session_start();
if ($action == "clear_field")
{
$_SESSION['field'] = "";
}
if ($action == "add_field")
{
if ($_SESSION['field'])
{
$count_field = count($field) + 1;
$field[] = "$count_field";
}
else
{
$_SESSION['field'] = $field;
$count_field = count($field);
$field[] = "$count_field";
}
}
?>
<form method=get action=<?php echo $_SERVER['PHP_SELF']; ?>>
parent name: <input type="text" name="parentname"><br>
children: <input type="text" name="child"> Age:<input type="text" name="ageforchild">
<?php
if ($_SESSION['field'])
{
foreach ($field as $count)
{
echo "<br>children $count: <input type=\"text\" name=\"child$count\" value=\"\">
Age $count:<input type=\"text\" name=\"ageforchild\">";
}
}
echo "<br><a href=\"$PHP_SELF?action=add_field\">Add Child Field</a>
<br><a href=\"$PHP_SELF?action=clear_field\">Clear Field</a>
<br><input type=\"submit\" name=\"submit\" value=\"submit\">";
?>
</form>
<?php
if(isset($_POST['submit']))
{
if ($_SESSION['field'])
{
foreach ($field as $count)
{
$parent = $_POST["parentname"];
$parentqry = "INSERT INTO parent (Name) VALUES ('$parent')";
mysql_query($parentqry, ServerConnect);
$child_name = "child$count";
$child_age = "ageforchild$count";
$qry="insert into child (ChildName, Age) values ('${$child_name}', ${$child_age})";
mysql_query($qry, $ServerConnect) or die (mysql_error());
}
}
}
?>