SUBMIT variable -- how do I

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
freewholly
Forum Newbie
Posts: 3
Joined: Thu May 09, 2002 3:05 pm

SUBMIT variable -- how do I

Post by freewholly »

Can you all tell me a good way to maintain data on my site? I have created a maintenance screen to Add, Edit and Search elements in the database. Delete, for me, is more difficult. I would like to add a Delete button to the Search results (one per row, or if it is cleaner, a checkbox per row instead of a button), but I don't know how to tell which row is to be acted upon. In other words, I can't tell which Delete button was clicked or which rows were checked. Do you have any advice?

David
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post by MattF »

The way I use for things like this is to have a link on the end of each line with the row id, for example delete.php?id=$id

Just add that onto the end of your loop that I assume you have to dump your SQL query into a table.
User avatar
sam
Forum Contributor
Posts: 217
Joined: Thu Apr 18, 2002 11:11 pm
Location: Northern California
Contact:

Post by sam »

I like the following:
form

Code: Select all

while($row = mysql_fetch_ass0c($result)){
    // do your normal displey stuff.
   echo "<input type=checkbox name="delete&#1111;]" value="".$row&#1111;"id"]."">";
&#125;
action

Code: Select all

foreach($delete as $row){
    if(mydql_query("DELETE FROM tablename WHERE id='".$row."'")){
         echo "Entry ".$row." was deleted.";
    }
}
I hope you understand the logic, it allows you to delete many rows at one time.

Cheers Sam
freewholly
Forum Newbie
Posts: 3
Joined: Thu May 09, 2002 3:05 pm

Post by freewholly »

Thanks for the suggestions. I'll try them and see.

David
Post Reply