Hi,
I have a parent and child form, with the child form connected to the parent form by the parent_id. The forms are on different pages, and i am trying to pass the id of the parent form to the child form using session variables.
What ive done (with no luck) is start a session after a parent entry is inserted into the database and store the id of the parent as a variable.
$query = "INSERT INTO parent (id, parent_name) VALUES ('','$parent_name')";
$result = mysql_query($query) or die(mysql_error());
session_start();
$id = $_SESSION['id'];
And try to pass the session variable into the child table by calling the variable in the child form, and insert it into the parent_id field of the child form:
<?php
session_start();
$_SESSION['id']
<form enctype="multipart/form-data" name="" action="" method="POST">
<table width="400" border="0">
<tr>
<td valign="top"><label for="parent_id"> Parent_id </label></td>
<td><input type="text" name="parent_id" id="parent_id" value="<?php echo $id ?>"/> </td>
</tr>
<tr>
<td valign="top"><label for="id"> Child</label></td>
<td><input type="text" name="id" id="id" /> </td>
</tr>
</table>
</form>
?>
I'm wondering maybe if i need to retrieve the parent_id first with a SELECT query before i start the session? If so, how i do make sure i'm retrieveing the parent that was just inserted? Any hints will be appreciated. Thanks