/    Sign up×
Community /Pin to ProfileBookmark

php refresh page

hi

is there a php function that I can add to my code to refresh the page after it comes to the end of my script.

thank you

to post a comment
PHP

15 Comments(s)

Copy linkTweet thisAlerts:
@delr2691Aug 27.2006 — no.. if you've already sent content, you can not "refresh" the page..

you can send some headers to change the location but just before sending any content..
[code=php]header("Location: http://your.domain.com/bla.php");[/code]

But you may wanna try JavaScript to do so..
Copy linkTweet thisAlerts:
@JickAug 27.2006 — You could echo a refresh meta tag at the end of the script just before it exits. Like this:[code=php]<?php
# Your script here...
# Your script here...
# Your script here...

echo('<meta http-equiv="refresh" content="20">');
?>[/code]
Could that work...? I'm not exactly sure if that will work but it was just an idea that popped into my head when I read your post. I'm sorry if it doesn't work. If it does, I hope that helps. ?
Copy linkTweet thisAlerts:
@kprocauthorAug 27.2006 — no, does nothing, thank you for taking time to post
Copy linkTweet thisAlerts:
@NogDogAug 27.2006 — First question: why do you need to refresh your page at the end of your script? (I can't think of a reason why you would, but that doesn't mean there isn't one.)
Copy linkTweet thisAlerts:
@kprocauthorAug 27.2006 — I have a form that deletes data from a table. The user chooses the item from the active page and presses the button. The item is deleted but they have to click a link to refresh the page.
Copy linkTweet thisAlerts:
@NogDogAug 27.2006 — Well, it seems if you did the form processing and database update and [i]then[/i] generated your page output, there would be no reason to refresh -- but maybe I'm missing something?
Copy linkTweet thisAlerts:
@kprocauthorAug 27.2006 — attached the code to give an idea what is happening. I working with the delete section

I thought that when I get the end the delete it would reload the table but no such luck


[code=php]
<?

include 'db.php';

$active_id = $_SESSION['user_id'];

$buddy_id = $_POST['addbuddy'];

$array = explode(",",$buddy_id);

$post_b_id = $array[0];
$first_name = $array[1];
$last_name = $array[2];


$query = mysql_query("SELECT * FROM buddylink WHERE owner_id ='$active_id'") or die ("Search Error" .mysql_error());

$tbl .= "<form name='dBuddy' method='post' action='addbuddy.php'>";
$tbl .='<table width="200" border="1" cellspacing="2">';
$tbl .='<tr>';
$tbl .='<td>Delete</td>';
$tbl .='<td width="303">Name:</td></tr>';

while($r=mysql_fetch_assoc($query)) {

$f_name = $r['first_name'];
$l_name = $r['last_name'];
$b_id = $r['buddy_id'];


$tbl .= "<tr><td align=center><input type=radio name='deletebuddy' value='$b_id'></td>";
$tbl .="<td><a href='SearchDetails.php?owner_id=$b_id'>$f_name $l_name</a></td></tr>";

}

$tbl .="</table>";
$tbl .= "<input align=left type='submit' name='submit' value='Delete>";
$tbl .= "</form>";

if($buddy_id != ""){

// ADD TO TABLE
$sql = mysql_query("INSERT INTO buddylink (owner_id, buddy_id, first_name, last_name, added)VALUES('$active_id', '$post_b_id', '$first_name', '$last_name', now())")or die ("Link Create Error:" .mysql_error());



}

$d_buddy = $_POST['deletebuddy'];

if($d_buddy != ""){

mysql_query("DELETE FROM buddylink WHERE buddy_id = '$d_buddy'");

echo 'Buddy has been deleted';



}
echo $tbl;

?>
[/code]
Copy linkTweet thisAlerts:
@delr2691Aug 27.2006 — you are creating the whole html output before deleting the entry.. the page wont show the updates not even when you add.. you can try this instead:

[code=php]
<?

include 'db.php';

$active_id = $_SESSION['user_id'];

$buddy_id = $_POST['addbuddy'];

$array = explode(",",$buddy_id);

$post_b_id = $array[0];
$first_name = $array[1];
$last_name = $array[2];





if($buddy_id != ""){

// ADD TO TABLE
$sql = mysql_query("INSERT INTO buddylink (owner_id, buddy_id, first_name, last_name, added)VALUES('$active_id', '$post_b_id', '$first_name', '$last_name', now())")or die ("Link Create Error:" .mysql_error());



}

$d_buddy = $_POST['deletebuddy'];

if($d_buddy != ""){

mysql_query("DELETE FROM buddylink WHERE buddy_id = '$d_buddy'");

echo 'Buddy has been deleted';



}




$query = mysql_query("SELECT * FROM buddylink WHERE owner_id ='$active_id'") or die ("Search Error" .mysql_error());

$tbl .= "<form name='dBuddy' method='post' action='addbuddy.php'>";
$tbl .='<table width="200" border="1" cellspacing="2">';
$tbl .='<tr>';
$tbl .='<td>Delete</td>';
$tbl .='<td width="303">Name:</td></tr>';

while($r=mysql_fetch_assoc($query)) {

$f_name = $r['first_name'];
$l_name = $r['last_name'];
$b_id = $r['buddy_id'];


$tbl .= "<tr><td align=center><input type=radio name='deletebuddy' value='$b_id'></td>";
$tbl .="<td><a href='SearchDetails.php?owner_id=$b_id'>$f_name $l_name</a></td></tr>";

}

$tbl .="</table>";
$tbl .= "<input align=left type='submit' name='submit' value='Delete>";
$tbl .= "</form>";

echo $tbl;

?>
[/code]


Hope that works.. ?
Copy linkTweet thisAlerts:
@kprocauthorAug 27.2006 — thank you for the reply are fixing up my code. I figured I was doing somthing wrong

I have been testing if user has posted by ($variable != ""){

code .............

}

Is this a good way to do this or is there a better way.
Copy linkTweet thisAlerts:
@delr2691Aug 27.2006 — Your welcome ?

And I guess you should do it this way.. [well, actually is the way I'm used to ?]
[code=php]
if (isset($_POST['input']) && !empty($_POST['input'])) {
//add, delete or anything here..
} else {
//just output the table
}
[/code]
Copy linkTweet thisAlerts:
@NogDogAug 27.2006 — Just be aware that when you do a "==" or "!=" comparison or when using the empty() function; the values 0 (zero), "" (empty string) and the boolean FALSE constant are all treated as equivalent. Therefore, if zero or a boolean false is a valid entry, then you should use "===" or "!==" against an empty string when doing your comparison. Plus, I normally trim() the inputs first to get rid of leading/trailing spaces:
[code=php]
foreach($_POST as $key => $val)
{
$_POST[$key] = trim($val);
}
if(isset($_POST['input']) and $_POST['input'] !== '')
{
// good to go
}
else
{
// missing a required entry
}
[/code]
Copy linkTweet thisAlerts:
@arcticwarrioJul 05.2012 — [code=php]header('Location: '.$_SERVER['PHP_SELF']);[/code]
Copy linkTweet thisAlerts:
@snipe42Jul 05.2012 — [code=php]header('Location: '.$_SERVER['PHP_SELF']);[/code][/QUOTE]

i use this,but inside a form.
[code=php]<form name='myform' method='post' action='".$_SERVER['PHP_SELF']."?action=del'>[/code]

but script for getting del action is above it.
[code=php]if ($_GET['action'] == "del")
{
// get the hidden value
$n = $_POST['n'];

for ($i=0; $i<=$n-1; $i++)
{
if (isset($_POST['NPM'.$i]))
{
$NPM = $_POST['NPM'.$i];
$query = "DELETE FROM mahasiswa WHERE NPM = '$NPM'";
mysql_query($query);
}
}
}
[/code]


it's didnt show you any message, but its actually refresh the page.
Copy linkTweet thisAlerts:
@AdelineZNov 21.2012 — Hi there!

I have a similar problem.

I want to delete from a table of mysql database. My problem is that after i delete a second record, only if i press 'Ctrl+F5' that record disapear.Meanwhile, from the database that record is deleted. What should i do? I have to complete that i'm working on apache server, on localhost, there was no problem.

Thanks !

This is the code:

[code=php]<?php
ob_start();

include "conectarebd.php";
$idul=$_GET['id'];
mysql_query("DELETE FROM angajator WHERE id='$idul' ") or die(mysql_error());

header('location: http://domain.ro/edit_angajator_button.php'.$random);

?>[/code]
Copy linkTweet thisAlerts:
@AdelineZNov 22.2012 — I forgot to remove '$random' from my code; that was another way that i tried to make it work, but it failed too.
×

Success!

Help @kproc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...