Form Buttons

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
User avatar
tmaiden
Forum Commoner
Posts: 64
Joined: Fri Feb 24, 2006 3:15 pm
Location: Philadelphia
Contact:

Form Buttons

Post by tmaiden »

How can I pass a vaule to the same page using a submit button.

Code: Select all

<?
 	....
 	if(isset($_GET['Delete']))
 	{
 		// Delete Row From Table
 	}
 	else
 	{
 		// Display Table With Delete & Reset Buttons
 		...
 		print '<TD>' . $row['id'] . '</TD>';
 		print '<TD><input type="submit" value="Reset"></TD>';
 		print '<TD><input type="submit" value="Delete"></TD></TR>'; 
 		...
 		print "</table></font></form>";
	}
?>


I want to pass "$row['id']" to the IF Statement, so I can delete from a table.

Any suggestions on how I can do this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

a form for each row?
User avatar
tmaiden
Forum Commoner
Posts: 64
Joined: Fri Feb 24, 2006 3:15 pm
Location: Philadelphia
Contact:

Post by tmaiden »

Yes, am I doing it incorrectly?
User avatar
tmaiden
Forum Commoner
Posts: 64
Joined: Fri Feb 24, 2006 3:15 pm
Location: Philadelphia
Contact:

Post by tmaiden »

Owe wait, no sorry. A form for ALL of the rows.
User avatar
tmaiden
Forum Commoner
Posts: 64
Joined: Fri Feb 24, 2006 3:15 pm
Location: Philadelphia
Contact:

Post by tmaiden »

I was hoping I could assign the $row['id'] to each button, then pull the id from the button and pass it into my delete query.

Code: Select all

Kinda like
<input type="submit" value="Delete" rowidnumber=$row['id']>

 	if(isset($_GET['Delete']))
 	{
 		// Delete Row From Table
 		$query = "DELETE * FROM table WHERE id = $rowidnumber";
 	}
I know that isn't really possible, but thats what im trying to accomplish.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Something like this will work, I wrote it based on your quote but it should help you. Modify it to suite your needs.

Code: Select all

<?php
    if(isset($_POST['rowidnumber']))
    {
       // Delete Row From Table
       $query = "DELETE * FROM table WHERE id = $rowidnumber";
    }
?>
<form name="blah" action="" method="post">
<input type="hidden" name="rowidnumber" value="<?php echo $row['id']; ?>" />
<input type="submit" value="Delete">
</form>
User avatar
tmaiden
Forum Commoner
Posts: 64
Joined: Fri Feb 24, 2006 3:15 pm
Location: Philadelphia
Contact:

Post by tmaiden »

agtlewis, would I have to treat each row as its own form?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It would require Javascript, and the page code wouldn't be standards compliant, but that is possible, albeit not exactly like you have it.

If you wish to avoid Javascript, depending on your page design, you can create standards compliant forms for each row that would allow for submission of that rows' data. Now, of course, the page layout is easier to do if you don't care for standards compliance. I'm referring to <form> being inside or outside table rows or cells.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

No you can just generate a id for each of the rows, and have a checkbox for each row with the id.

I think.

EDIT: Sample Of What I mean

Code: Select all

<td><input type="checkbox" value="<?php echo $row['ID']; ?>"></td><td><?php echo $row['ID']; ?></td>
Post Reply