hello i have a problem with mysql; i want to create a web app to manage the charges; and in this page the user will create a month and add the charges of the month i have three tables here, table year (ID; year) table month (ID, month, id_year) and table charges (ID, designation, description, value, ID_month) when the user select the month that he wants he add the charges and click submit; the month should be add to the table month and in the same time the charges are added to table charges, the problem is i need the month ID to add it to table charges so i select it after the first the 'multi request' is done then i try to update the table charge by adding the month id but it doesn't work, i get this error 'Commands out of sync; you can't run this command now' here is the code please help me to find a solution how to do it plz thank you

//--test POST vars
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        //test inputs from functions.php
        $month = test_input($_POST['month']);

    //year from url GET
    $year = 2000;
    $sql_year = "SELECT ID FROM year WHERE year = '" . $year . "' ";
    $year_result = mysqli_query($conn, $sql_year);
    $year_fetch = mysqli_fetch_assoc($year_result);
    $year_ID = $year_fetch['ID'];
    //check if month already exist
    $check_month = "SELECT ID FROM month WHERE month = '" . $month . "' AND year_ID = '" . $year_ID . "'";
    $month_result = mysqli_query($conn, $check_month);
    if (mysqli_num_rows($month_result) == 1) {
        //if it exist do nothing but set error msg
        $msgerr = $lang['addmonth-error-monthexist'];
    } else {
        //insert month and year ID in month table
        $sql = "INSERT INTO month (month, year_ID) VALUES ('" . $month . "','" . $year_ID . "');";

        //depending on how many charges were set do the test inputs and add to sql db
        foreach ($_POST['charge'] as $iq => $val) {

            $charge[$iq] = test_input($val);
            $description[$iq] = test_input($_POST['description'][$iq]);
            $value[$iq] = test_input($_POST['value'][$iq]);

            $sql .= "INSERT INTO charges (designation, description, value) VALUES ('" . $charge[$iq] . "','" . $description[$iq] . "','" . $value[$iq] . "');";

        }

        if ($reslult = mysqli_multi_query($conn, $sql) === TRUE) {

            $msgs = $lang['message_succ_datasaved'];
        } else {
            $msge = $lang['message_errorgen'];
        }

        //Select the add month's ID
            $msql= "SELECT ID FROM month WHERE month = '".$month."' && year_ID = '".$year_ID."' ";
            $month_idqu = mysqli_query($conn,$msql);
            if (!$month_idqu) {
echo 'MySQL Error: ' . mysqli_error($conn);
exit;
}
                $month_id = mysqli_fetch_assoc($month_idqu);


            $charge_up = mysqli_query($conn, "UPDATE charges SET month_ID = '".$month_id."' WHERE ID = '".$charge_id."' ");
    }//end else if month exist
}//end if request method  
    Write a Reply...