Solved

How do I make this Refresh work when processing a form

Posted on 2011-02-23
6
366 Views
Last Modified: 2013-12-13
Experts,
How do I make the 'Refresh' function work and go to the desired URL after processing a form script.  Everything works on the script except for the refresh.  (This same script with refresh works just fine on another script)  

When I run the script, I get the following information in the returned data from my echo statements:
2
02-23-2011
Sample Comment
2  

This is the only thing not working on the page:
header("Refresh: 0;url=http://www.url.com/NewSite/seniorwatch_viewrecord.php?id='".$id."'");

Thanks for your help!
<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','Date');
pt_register('POST','id');
pt_register('POST','comment');
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Date: ".$Date."
Date: ".$Date."
ID: ".$id."
Notes: ".$comment."
";
$message = stripslashes($message);
echo $id;
echo $Date;
echo $comment;
mail("my_email","Org",$message,"From: Me");
$link = mysql_connect("HOST","UN","PW");
mysql_select_db("DB",$link);
$query="INSERT into `comments` (id, comment, Date) values ('".$id."','".$comment."','".$Date."')";
mysql_query($query);
header("Refresh: 0;url=http://www.url.com/NewSite/seniorwatch_viewrecord.php?id='".$id."'");
echo $id;
}
?>

Open in new window

0
Comment
Question by:rlb1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 4

Assisted Solution

by:racastillojr
racastillojr earned 100 total points
ID: 34966402
try puting this in the head tag:

<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.url.com/NewSite/seniorwatch_viewrecord.php?id='".$id."'">
0
 
LVL 4

Expert Comment

by:racastillojr
ID: 34966408
the number in the content section is how many seconds before the page is refreshed
0
 
LVL 11

Assisted Solution

by:Ovid Burke
Ovid Burke earned 100 total points
ID: 34966693
If you put it in the HEAD of your HTML, you will also need to establish some sort of condition with php so that is does not go before you submit the form. However if the idea is to go to a different page right after PHP successfully processes your form, you should use:

header("Location: http://www.url.com/NewSite/seniorwatch_viewrecord.php?id=$id");

Open in new window

0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 6

Accepted Solution

by:
MatthewP earned 300 total points
ID: 34966704
Do you mean to have the single quotes round the id? You are trying to send it to http://www.url.com/NewSite/seniorwatch_viewrecord.php?id='your-id-here'

ie the single quotes are part of the url.

As you don't need to build up the string using double quotes you should find that this works fine:

header("Refresh: 0;url=http://www.url.com/NewSite/seniorwatch_viewrecord.php?id=$id");
0
 
LVL 6

Expert Comment

by:MatthewP
ID: 34966726
The above will work with single quotes in the url too if they are required for some reason.

You will have problems sending headers if you break the string (ie where the " are) - you should always keep the whole header to one set of single quotes and drop any variables in inside them.

0
 

Author Closing Comment

by:rlb1
ID: 34966940
Thanks Matthew P!  It worked great!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question