Page 1 of 1

How to use hyperlinks to remove data from DB

Posted: Thu Jun 13, 2002 11:56 am
by scrtagt69
I have a form which displays one employee record at a time, with different training courses and a link next to each course to Remove the course from MySQL. The problem is, is when I click on the link to delete a course, it removes it from the DB, but it physically stays on the page until the page is refreshed. I want something like PHPMYADMIN when a record is deleted the browser is refreshed automatically and that one row is now gone. The form comes from a previous page where the admin can click on an employee name to display these courses with this:

Code: Select all

echo "<a href='markcourse.php?key=$row&#1111;Empkey]&lastname=$row&#1111;LastName]&firstname=$row&#1111;FirstName]'>$row&#1111;LastName],&nbsp;$row&#1111;FirstName]</a>\r\n";
I do have the form Cached with the following code:

Code: Select all

//sets expires to date in the past, last modified to current time 
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 
header ("Pragma: no-cache"); // HTTP/1.0
And heres the code I have to display the link and the query to delete it:

Code: Select all

if (isset($act))  

mysql_query("DELETE FROM Schedule WHERE Schkey= '$act'") or die(mysql_error());


echo "<a onclick='return confirmSubmit()'href = "$PHP_SELF?key=$userkey&lastname=$lname&firstname=$fname&act=$rows&#1111;Schkey]">Remove</a>\r\n";


I hope its clear as to what Im trying to do....does anyone know why this is happening?? Thanks for any help

Posted: Thu Jun 13, 2002 1:47 pm
by DSM

Code: Select all

$refresh_url = "page_name.php";	
                header("Location:$refresh_url");

Posted: Thu Jun 13, 2002 4:21 pm
by scrtagt69
hey dsm,

i put this in

Code: Select all

$refresh_url = "$PHP_SELF?key=$userkey&lastname=$lname&firstname=$fname";    
                header("Location:$refresh_url");
at the very beginning of my code and it gave me an error that header cant be sent. Its the very first line in my code. Where should I place it??

Posted: Thu Jun 13, 2002 4:27 pm
by DSM
If you have the delete query in your display page I would put it here.

Code: Select all

if (isset($act)):  

mysql_query("DELETE FROM Schedule WHERE Schkey= '$act'") or die(mysql_error()); 

$refresh_url = "$PHP_SELF?key=$userkey&lastname=$lname&firstname=$fname";    
                header("Location:$refresh_url");
endif;

Posted: Thu Jun 13, 2002 5:07 pm
by scrtagt69
i did that DSM and this is the error it gave me

Warning: Cannot add header information - headers already sent by (output started at D:\php\markcourse.php:29) in D:\php\markcourse.php on line 152
Any clues??
By the way I appreciate the help, you are the only who has even attempted to help with this through 3 different forums.

Posted: Thu Jun 13, 2002 5:23 pm
by hob_goblin
well "Warning: Cannot add header information - headers already sent by (output started at D:\php\markcourse.php:29) in D:\php\markcourse.php on line 152"

would imply, that headers were output, (this can be html being printed) on line 29, and you put the headers on line 152,

make sure nothing is echoed, printed, etc...before you output the header

Posted: Thu Jun 13, 2002 5:45 pm
by scrtagt69
thanks for your help DSM...worked great