Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

refresh submit problem

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

refresh submit problem

Postby speedamp » Tue Dec 02, 2003 12:48 pm

hello.

I am submitting a form, and then would simply like to refresh the page (or redirect to the same page).

Can somebody tell me what i'm doing wrong?

---------------------------------------------------------------------------------

if($submit){
$sql = "UPDATE runner SET run_id='$run_id',club='$club',first='$first',last='$last',age='$age',sex='$sex',race='$race' WHERE run_id=$run_id";
$result=mysql_query($sql);
echo"Thank you! Information updated.\n";
header("Location:".$_SERVER['PHP_SELF']."");
} elseif ($delete) {

// delete a record

$sql = "DELETE FROM runner WHERE run_id=$run_id";

$result = mysql_query($sql);

echo "$sql Record deleted!<p>";

header("Location:".$_SERVER['PHP_SELF']."");
------------------------------------------------------------------------------------


How would I echo the message "record deleted", wait 5 seconds, and then refresh the page?

-Michael
speedamp
New php-forum User
New php-forum User
 
Posts: 19
Joined: Sun Nov 16, 2003 9:12 am

Postby swirlee » Tue Dec 02, 2003 12:51 pm

You can't use the header() function after you've sent output (text, HTML, whitespace, anything) to the browser. If you want to send the user to another page after a given number of seconds, use the META refresh tag: http://www.pageresource.com/html/metref.htm
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby speedamp » Tue Dec 02, 2003 1:09 pm

Yes, that seems to be the way to go, but how can i pass the php variables in the header?

Right now it simply prints the url on the screen:

$result=mysql_query($sql);

echo"Thank you! Information updated.\n";
echo "<meta http-equiv='refresh' content='5; url=http://www.rasnaheireann.com/register/editform/edit.php?clubname=".$clubname. ">";


-Michael
speedamp
New php-forum User
New php-forum User
 
Posts: 19
Joined: Sun Nov 16, 2003 9:12 am

header

Postby ruturajv » Wed Dec 03, 2003 3:10 am

You can pass the variables for redirecting as
Code: Select all
header("location: page.php&varname".$varname);
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.