Reputation: 260
I am currently creating a podcast website where I have a form for my users to enter a comment on the current episode they are listening to.
All my content is stored in mysql and data on my episode page is displayed like so
http://www.mysite.com/episode.php?id=1
With separate content for the episode.
On this post adding to database no repeat on refresh
I mentioned about the form resubmitting on refresh which is why I added
header('Location: index.php');
However. I would like this to visit the same page with a thank you message echoed.
I have tried
header('Location: episode.php?id=<?php echo $data['cast_id']; ?>');
echo "thank you";
But this brings back the error Parse error: syntax error, unexpected T_STRING
Please can someone advise me on the best way to do this? Thank you.
Upvotes: 1
Views: 129
Reputation: 5183
header('Location: episode.php?id=<?php echo $data['cast_id']; ?>');
you are using php tags in already started php tags.
you can simply do this ..
session_start(); // make sure session is up and running
// just before redirecting
$_SESSION['thankyou_msg'] = 1;
header('Location: episode.php?id='.$data['cast_id']);
now on index.php.
session_start();
if(isset($_SESSION['thankyou_msg'])){
echo "your thankyou message here";
unset($_SESSION['thankyou_msg']);
}
Upvotes: 1
Reputation: 8179
header()
function is php function, so why you start php in it?
Also add exit()
and store message in SESSION
variable.
$_SESSION['msg'] = "thank you";
header("Location: episode.php?id=$data['cast_id']");
exit();
Upvotes: 1