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 '<ul>';


    while($row = mysql_fetch_array($resultMainMenu))
    { 
        echo '<form action=page.php method=post>';
            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_array($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 '</form>';
    }
    echo'</ul>';

I've tried to fix this since yesterday but I can't figure it out. My code is only updating the last record (the menus with no sub-menus or the last sub-menu of a menu) and not all of them as it should. Help please !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.