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
Printable View
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
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..
But you may wanna try JavaScript to do so..PHP Code:header("Location: http://your.domain.com/bla.php");
You could echo a refresh meta tag at the end of the script just before it exits. Like this: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. :)PHP Code:<?php
# Your script here...
# Your script here...
# Your script here...
echo('<meta http-equiv="refresh" content="20">');
?>
no, does nothing, thank you for taking time to post
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.)
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.
Well, it seems if you did the form processing and database update and then generated your page output, there would be no reason to refresh -- but maybe I'm missing something?
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
PHP Code:<?
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;
?>
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:
Hope that works.. :)PHP Code:<?
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;
?>
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.
Your welcome :)
And I guess you should do it this way.. [well, actually is the way I'm used to :D]
PHP Code:if (isset($_POST['input']) && !empty($_POST['input'])) {
//add, delete or anything here..
} else {
//just output the table
}
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:
PHP Code:foreach($_POST as $key => $val)
{
$_POST[$key] = trim($val);
}
if(isset($_POST['input']) and $_POST['input'] !== '')
{
// good to go
}
else
{
// missing a required entry
}
PHP Code:header('Location: '.$_SERVER['PHP_SELF']);
i use this,but inside a form.
but script for getting del action is above it.PHP Code:<form name='myform' method='post' action='".$_SERVER['PHP_SELF']."?action=del'>
it's didnt show you any message, but its actually refresh the page.PHP Code: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);
}
}
}
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:
PHP Code:<?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);
?>