fanir miah tarafdar fanir miah tarafdar - 1 year ago 68
PHP Question

How to make site redirect to same page before refreshing - PHP

I am trying to make the user redirect back to the

#contact page
before refreshing. But when clicking send message the site goes back to the first page and I have to scroll all the way down to
#contact page
and then 5 seconds later it refreshes back to the first page (which is good). My code is below:




$error= "<br/>-Please enter your name" ;


$error.= "<br/>-Please enter your email" ;


if (trim($_POST['message']) == "")
$error.= "<br/>-Please enter message";

$error.= "<br/>-Please enter your contact number" ;


if ($error){
$result= "Whoops, error: $error";


mail('', "Contact message", "Name: ".$_POST['name']." Email: ".$_POST['email']."
Email: ".$_POST['name']."
Message : ".$_POST['message']."
Contact :".$_POST['contact'] );
// header("location:index.php#contact");
header( "refresh:5; url = index.php#contact" ); //wait for 5 seconds before redirecting

$result= "Thankyou, Ill be in touch shortly";





I have commented out one header or else the
wont show in the contact form. How can I make it that when user sends message instead of going back to first page it redirects back to the
page still displaying the
and later refresh.

Answer Source

From what I understand you would like to go to #contact just after submitting and then five second later the page will be refreshed and go to #contact ?

In that case, you might want to add #contact in your form action :

<form action="mypage.php#contact">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download