How can conditional statements be used effectively to execute different PHP code based on form submissions on the same page?

To execute different PHP code based on form submissions on the same page, you can use conditional statements to check which form was submitted and then execute the corresponding code block. You can achieve this by checking the value of a hidden input field in each form that identifies the form being submitted. Based on this value, you can determine which code block to execute.

if(isset($_POST['form1_submit'])) {
    // Code to execute when form 1 is submitted
} elseif(isset($_POST['form2_submit'])) {
    // Code to execute when form 2 is submitted
} else {
    // Code to execute when no form is submitted
}