Posting to same page and different page through form

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
hibbeac1
Forum Newbie
Posts: 13
Joined: Thu Oct 30, 2003 10:25 am

Posting to same page and different page through form

Post by hibbeac1 »

Hi everyone,

As a part of a website i am making i have a form which you select items using a checkbox and then you can delete them. However i would also like to be able to select these and if the user presses edit it will take them to a different page and still transport what they have selected so then another form will come up so they can edit the item they have selected. But i am not sure on how to do this can one form have several actions, or is there another way to do this. Code at moment is:

Code: Select all

form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<TABLE border = "1"  cellspacing="0" cellpadding="3">
<TR><TD colspan="4"  bgcolor="#0099FF"><b><CENTER>Tasks</CENTER></b></td>
<TR><TD colspan="4"  bgcolor="#c0c0c0"></td>
<!-- <TR><TD align="right" bgcolor="#c0c0c0">User To Delete</td></td><td bgcolor="#c0c0c0"> -->
<tr><td align = "left" width = "1.25%" bgcolor = "#c0c0c0"><b>Select</td><td width = "1.25%" bgcolor = "#c0c0c0"><b>Task ID</td><td width = "80%" bgcolor = "#c0c0c0"><b>Subject</td><td width = "17.5" bgcolor = "#c0c0c0"><b>Due Date</b></td></tr>

<?php
	$userid = $_SESSION['user_id'];
	$query = "SELECT tasks.task_id, tasks.subject, DATE_FORMAT(tasks.duedate, '%e/%m/%Y') AS dd FROM tasks, taskregister WHERE taskregister.user_id='$userid' AND taskregister.task_id = tasks.task_id";
	$result = @mysql_query($query);
	while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
echo "<TR><TD align="left" bgcolor="#c0c0c0"><input type = "Checkbox" name="TaskDelete[]" value={$row['task_id']}></td><td bgcolor="#c0c0c0">{$row['task_id']}</td><td bgcolor="#c0c0c0">{$row['subject']} </td><td bgcolor="#c0c0c0">{$row['dd']}<br></td></tr>";
	}
?>

</TABLE>
<div align=center />
<p>
<input type="image" src="images/delete.png">   
<input type="hidden" name="Delete">  
</form>
<?php
if (isset($_POST['Delete'])) {
	
	if (isset($_POST['TaskDelete']) && (count($_POST['TaskDelete'] > 0))) {
		$a = $_POST['TaskDelete'];
		$i = 0;
		foreach ($a as $v) {
			$query= "DELETE FROM tasks WHERE task_id=$a[$i]";
			mysql_query($query) or die (mysql_error());
			$i++;
		}
	}
	}
?>
If anyone can suggest how i can do this i would be grateful

(Added eyecandy coloring - infolock)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

is the second script on the same server?
If so you might send the form to one script and include another one depending on the necessary action

see also: http://php.net/include
Post Reply