Complex MySQL Insert, what's wrong?
Posted: Sun Mar 06, 2005 4:39 am
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.
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.
Code: Select all
<?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());
}
}
}
?>