Here is the code. I want it this way --
Form submission --> page2.php --> redirect --> page1.php (Here is the message. Pop-up or whatever)
page1.php
<form action="page2.php" method="post" enctype="multipart/form-data" class="form-inline subscribe-form">
<input type="name" name="name" placeholder="Jack">
</div>
<button type="submit" name="sub" value="sub" >Submit</button>
</form>
page2.php
<?php
//include necessary
if(isset($_POST['sub'])) {
$nameget = mysqli_real_escape_string($dbconnect, $_POST['name']);
$sqlentry = .....bla bla......//insert into DB
}
$getsql = mysqli_query($dbconnect, $);
if($getsql){
mysql_close($dbconnect);
header('location:page1.php');
}
?>
Display Success Message After Form Submit- MetForm # At first, click any old page or post or create new. After that, create a new form or add any existing form to it. Just enable the Response Message Type to Sweet Alert while editing or creating a form with MetForm and you are done.
The best way to solve this problem is set a session message after the success of your operation in the process page. Then in the redirected page check whether the session message is set or not. If it is set then simply echo that message. The below code may help you.
If you want the same form page displayed again after submission with results, you will make the action the same page and include the processing script at the beginning of the file. Instead of echoing the result message within the processor as you have, store it as a variable which can be output in the html form page.
Where you have:
header('location:page1.php');
append a variable on the location, like:
header('location:page1.php?status=success');
And on page1.php, do something like:
if( $_GET['status'] == 'success'):
echo 'feedback message goes here';
endif;
This way your flash message will not show up again and again after refresh.
<?php session_start();
if(isset($_SESSION['msg']) && $_SESSION['msg'] != ''){
echo $_SESSION['msg'];
unset($_SESSION['msg']);
}
?>
<form action="page2.php" method="post"
enctype="multipart/form-data" class="form-inline subscribe-form">
<input type="name" name="name" placeholder="Jack">
</div>
<button type="submit" name="sub" value="sub" >Submit</button>
</form>
And
<?php
session_start();
//include necessary
if(isset($_POST['sub'])) {
$nameget = mysqli_real_escape_string($dbconnect, $_POST['name']);
$sqlentry = .....bla bla......//insert into DB
}
$getsql = mysqli_query($dbconnect, $);
if($getsql){
mysql_close($dbconnect);
$_SESSIOM['msg'] = 'Value Inserted or whatever';
header('location:page1.php');
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With