How to use hyperlinks to remove data from DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scrtagt69
Forum Newbie
Posts: 6
Joined: Thu Jun 13, 2002 11:56 am

How to use hyperlinks to remove data from DB

Post 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
DSM
Forum Contributor
Posts: 101
Joined: Thu May 02, 2002 11:51 am
Location: New Mexico, USA

Post by DSM »

Code: Select all

$refresh_url = "page_name.php";	
                header("Location:$refresh_url");
scrtagt69
Forum Newbie
Posts: 6
Joined: Thu Jun 13, 2002 11:56 am

Post 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??
DSM
Forum Contributor
Posts: 101
Joined: Thu May 02, 2002 11:51 am
Location: New Mexico, USA

Post 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;
scrtagt69
Forum Newbie
Posts: 6
Joined: Thu Jun 13, 2002 11:56 am

Post 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.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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
scrtagt69
Forum Newbie
Posts: 6
Joined: Thu Jun 13, 2002 11:56 am

Post by scrtagt69 »

thanks for your help DSM...worked great
Post Reply