Hi,
i have been trying in vain all day to assign child name to a parent id in an innodb table with foreign key. I can retrieve the parent id fine, but the problem is when i try to insert child name, PHP doesn't seem to be passing any values .... i would really appreciate someone having a look please
<?php include("database.php");
$id = $_GET['id'];
$query = "SELECT * FROM parent WHERE id=$id";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array( $result ); // Get selected entry ?>
<form name="test_fk" action="test_exec.php" method="POST">
<table >
<tr>
<td valign="top"><label for="id"> Parent id </label></td>
<td><input type="text" disabled="disabled" name="id" id="id" value="<?php echo $row['id']; ?>" /> </td>
</tr>
<tr>
<td valign="top"><label for="child_name"> Child name </label></td>
<td><input type="text" name="child_name" id="child_name" value="" /> </td>
</tr>
<tr>
<td> </td>
<td><input name="Submit" type="submit" value="Save "/></td>
</tr>
</table>
</form>
and this is the code that i can't get to work ... passing the parent_id to the child table ... i know its something to do with the values, i just don't know what/how ...
include("database.php");
if(isset($_POST[Submit])){
$id = $_GET['id'];
$id = $_POST['parent_id'];
$query = "INSERT INTO child (id, parent_id, child_name) VALUES ('','$_POST[parent_id]','$_POST[child_name]')";
echo $query;
$result = mysql_query($query) or die('MySQL query failed. ');
} // End else
echo $child_name;