在PHP中取消设置会话并使用onClick仅使用1个按钮提交表单

I need to submit a form and unset the session on submit at the same time on click.

This is currently my form and button :

<form method="post" action="" id="formID">
    //content here
    <button class="btn btn-success" type="submit" name="submit_req" value="submit_req" 
        onclick="submitForm('insert_man_order.php')">Submit Request</button>
</form>

This is my PHP for unsetting the session and resetting the value of my variable :

if(isset($_POST['submit_req'])){
    if(!empty($_SESSION['cart'])){
        foreach($_POST['quantity'] as $key => $val){
            $val == 0;
            unset($_SESSION['cart'][$key]);
        }
    }
}

JS :

function submitForm(action)
{
    document.getElementById('formID').action = action;
    document.getElementById('formID').submit();
}

The form submission is working but the session and $val are not unsetting/resetting. Any help will be appreaciated.

Thanks

Use session_unset() to destory all session variables. If it doesn't work you can try below snippet to totally delete everything and start new.

session_unset();
session_destroy();
session_write_close();
setcookie(session_name(),'',0,'/');
session_regenerate_id(true);

change $val==0 to $val=0 it will help you. thanks