0

THIS IS THE THE MAIN-PAGE.PHP upon clicking on the add button a modal will appear

THIS IS THE FORM THAT I PUT IN A BOOTSRAP MODAL, the form has an action="add.php" which is a seperated php file

this is the add.php code, I don't know how to display the $status on main-page.php because it is in the add.php file.

$run_sql = mysqli_query($conn, $sql)  or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($conn), E_USER_ERROR);
if ($run_sql===true){
    move_uploaded_file($tmp_profile_img,"upload/$profile_img");

    $status = '<div class="alert alert-info alert-dismissible fade show" role="alert">
    <strong>The data has been inserted SUCCESSFULLY</strong> You should check in on some of those fields below.
    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
  </div>';
}
else{
    $status = '<div class="alert alert-warning alert-dismissible fade show" role="alert">
    <strong>The data was NOT inserted SUCCESSFULLY</strong> Please try again.
    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
  </div>';
}

header("Location:main-page.php");
?>

2 Answers2

1

You can send query to the main-page.php , like this

header("Location:main-page.php?status=success");

in the main-page.php, you can get it, link this

$status = isset($_GET["status"]) ? $_GET["status"] : null
abofazl rasoli
  • 116
  • 1
  • 4
0

this worked main-page.php

<?php 
            if(isset($_GET['status']) AND $_GET['status'] == 'success'){
                echo '<div class="alert alert-info alert-dismissible fade show" role="alert">
                <strong>Holy guacamole!</strong> You should check in on some of those fields below.
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
              </div>';
             }elseif(isset($_GET['status']) AND $_GET['status'] == 'fail'){
                echo '<div class="alert alert-warning alert-dismissible fade show" role="alert">
                <strong>Holy guacamole!</strong> You should check in on some of those fields below.
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
              </div>';
             }else{
                echo '<div class="alert alert-info alert-dismissible fade show" role="alert">
                <strong>Holy guacamole!</strong> You should check in on some of those fields below.
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
              </div>';
             }
        ?>

add.php

$run_sql = mysqli_query($conn, $sql)  or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($conn), E_USER_ERROR);
if ($run_sql===true){
    move_uploaded_file($tmp_profile_img,"upload/$profile_img");
    header("Location:main-page.php?status=success");
}
else{
    header("Location:main-page.php?status=fail");
}

but I don't know if it's a clean code