I'm trying to figure it out why my code it's only updating the last menu or submenu of a menu. The menu and submenu are stored in the same database and the parent_id is equal to the id for the sub-menus . Parent_id = 0 means it's a main menu. Help!
$con = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $con);
if(isset($_POST['update']))
{
$sql = "UPDATE `menus` SET Menu_bar = '".$_POST['menu_bar']."' WHERE ID = ".$_POST['hidden'];
mysql_query( $sql, $con );
}
$resultMainMenu = mysql_query("SELECT * FROM menus WHERE Parent_id=0 ") or die(mysql_error());
echo '<form action=page.php method=post>';
while($row = mysql_fetch_assoc($resultMainMenu))
{
echo '<ul>';
echo "<li><input type=submit name=update value=update><input type=hidden name=hidden value='".$row['ID']."'><input type=text name=menu_bar value='".$row['Menu_bar']."'><br/>" ; // echo main menu
$resultSubmenu = mysql_query("SELECT * FROM menus WHERE Parent_id = " . $row['ID']) or die(mysql_error());
echo '<ul>';
while($rowSub = mysql_fetch_assoc($resultSubmenu))
{
echo "<li><input type=submit name=update value=update><input type=hidden name=hidden value='".$rowSub['ID']."'><input type=text name=menu_bar value='".$rowSub['Menu_bar']."'><br/></li>"; // echo sub menu
}
echo '</ul>';
echo '</li>';
echo'</ul>';
}
echo '</form>';
?>