karl_009 Posted February 26, 2009 Share Posted February 26, 2009 Hello, I have this code and it displays messages after the form is submitted, how I would go about redirecting this to another page and a popup message saying successful. I believe it will be the IF statement at the end that I will need to update? Here is the code that I am using now; <?php require ($_SERVER['DOCUMENT_ROOT']."cmstesting/config/db_config.php"); $connection = mysql_connect ($db_host, $db_user, $db_pass) or die ("Error with Connection"); mysql_select_db ($db_name, $connection); $conid = $_POST["conid"]; $submitted = $_POST["submitted"]; $query = "UPDATE contacts SET title='{$_POST["title"]}', first='{$_POST["first"]}', last='{$_POST["last"]}', suffix='{$_POST["suffix"]}', company='{$_POST["company"]}', address1='{$_POST["address1"]}', address2='{$_POST["address2"]}', city='{$_POST["city"]}', town='{$_POST["town"]}', country='{$_POST["country"]}', postcode='{$_POST["postcode"]}', website='{$_POST["website"]}', email='{$_POST["email"]}', hp1='{$_POST["hp1"]}', hp2='{$_POST["hp2"]}', hp3='{$_POST["hp3"]}', mp1='{$_POST["mp1"]}', mp2='{$_POST["mp2"]}', mp3='{$_POST["mp3"]}', notes='{$_POST["notes"]}' WHERE conid='$conid'"; $result = mysql_query($query); if ($result) { echo "Successful"; echo "<BR>"; echo "<a href='contact_view.php'>View</a>"; } else { echo "ERROR"; } ?> Thanks Karl Quote Link to comment https://forums.phpfreaks.com/topic/147010-solved-popup-message-after-form-submitted/ Share on other sites More sharing options...
allworknoplay Posted February 26, 2009 Share Posted February 26, 2009 if ($result) { header("Location: http://$host$uri/contact_view.php"); } Because you're using header function, you need to have this at the top of your script, you cannot output anything before the header function.... Quote Link to comment https://forums.phpfreaks.com/topic/147010-solved-popup-message-after-form-submitted/#findComment-771787 Share on other sites More sharing options...
karl_009 Posted February 26, 2009 Author Share Posted February 26, 2009 Thanks for that, the page now redirects to the page... Is there away to have a popup message popup, then continue on to the page... <?php if ($result) { // echo "Successful"; // echo "<BR>"; // echo "<a href='contact_view.php'>View</a>"; echo "<script type='text/javascript'>alert('Successful')</script>"; header("Location: http://localhost/cmstesting/contact_view.php"); } else { echo "ERROR"; } ?> I have included; echo "<script type='text/javascript'>alert('Successful')</script>"; Is there away to execute this code then the header code after this has been OK... Many Thanks Karl Quote Link to comment https://forums.phpfreaks.com/topic/147010-solved-popup-message-after-form-submitted/#findComment-771820 Share on other sites More sharing options...
allworknoplay Posted February 26, 2009 Share Posted February 26, 2009 Thanks for that, the page now redirects to the page... Is there away to have a popup message popup, then continue on to the page... <?php if ($result) { // echo "Successful"; // echo "<BR>"; // echo "<a href='contact_view.php'>View</a>"; echo "<script type='text/javascript'>alert('Successful')</script>"; header("Location: http://localhost/cmstesting/contact_view.php"); } else { echo "ERROR"; } ?> I have included; echo "<script type='text/javascript'>alert('Successful')</script>"; Is there away to execute this code then the header code after this has been OK... Many Thanks Karl No, what you should do is load that script on the new page on the top...this way right before the new page loads, you load the pop up... Quote Link to comment https://forums.phpfreaks.com/topic/147010-solved-popup-message-after-form-submitted/#findComment-771828 Share on other sites More sharing options...
karl_009 Posted February 26, 2009 Author Share Posted February 26, 2009 I found a solution, it did not use PHP but I thought I would post it anyway. <?php if ($result) { // Successful popup message, redirected back to view contacts echo "<script type='text/javascript'>alert('Successful - Record Updated!'); window.location.href = 'contact_view.php';</script>"; } else { // Unsuccessful popup message, redirected back to view contacts echo "<script type='text/javascript'>alert('Unsuccessful - ERROR!'); window.location.href = 'contact_view.php';</script>"; } ?> Thanks for the replies Karl Quote Link to comment https://forums.phpfreaks.com/topic/147010-solved-popup-message-after-form-submitted/#findComment-771884 Share on other sites More sharing options...
allworknoplay Posted February 26, 2009 Share Posted February 26, 2009 I found a solution, it did not use PHP but I thought I would post it anyway. <?php if ($result) { // Successful popup message, redirected back to view contacts echo "<script type='text/javascript'>alert('Successful - Record Updated!'); window.location.href = 'contact_view.php';</script>"; } else { // Unsuccessful popup message, redirected back to view contacts echo "<script type='text/javascript'>alert('Unsuccessful - ERROR!'); window.location.href = 'contact_view.php';</script>"; } ?> Thanks for the replies Karl Good script, I will save that script myself for future purposes... Quote Link to comment https://forums.phpfreaks.com/topic/147010-solved-popup-message-after-form-submitted/#findComment-771902 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.