ltbaggz Posted January 8, 2007 Share Posted January 8, 2007 I am using a loop to display form buttons to remove certain items from a database. I have tried a couple of different styles and although it will work in firefox it will not work in internet explorer. I am displaying a delete record button with a value of a distinct entry in the database.here is a snippet from my code[code]<form method="post" action="do_it.php"><li id="list_item"><button name="delete" value="72" type="submit">Delete</button></li><li id="list_item"><button name="delete" value="77" type="submit">Delete</button></li></form>[/code]this is what my php script generates, ie will not recognize the submit. if i use input tags then i am also having a input hidden value with the database record to be deleted as well as the button and when i access it in the $_POST variable it does not contain the correct value of the record to be deleted. I am not sure how to make this name value unique and then be able to access it in the $_POST when i run my query. hopefully i explained in a way that can be understood.ThanksDrew Quote Link to comment Share on other sites More sharing options...
fenway Posted January 8, 2007 Share Posted January 8, 2007 Why not use INPUT type=button? Quote Link to comment Share on other sites More sharing options...
ltbaggz Posted January 8, 2007 Author Share Posted January 8, 2007 if i use a input button then i need a hidden value as well to be able to pass the id to delete. when my php generates this form it can have any number of entries, the name="delete" is the same for all of the different buttons to choose from and when it is submitted, the $_POST variable does not contain the proper id to delete. this is because im declaring multiple inputs with the same name. I could change the script to append an index onto the name but then how do i determine what button is pressed, when i check for it in my script? hope this makes sense. Quote Link to comment Share on other sites More sharing options...
sloshire1 Posted January 8, 2007 Share Posted January 8, 2007 How about something like this:<input type="image" src="/images/delete.gif" name="Delete" value="77"><br><input type="image" src="/images/delete.gif" name="Delete" value="78"><br><input type="image" src="/images/delete.gif" name="Delete" value="79"><br>...You would need to create a delete button image, but it would work. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted January 9, 2007 Share Posted January 9, 2007 you should only use name once in a form unless its for radio buttons. Quote Link to comment Share on other sites More sharing options...
fenway Posted January 9, 2007 Share Posted January 9, 2007 Why can't you name the input type=button with the uid? Quote Link to comment Share on other sites More sharing options...
weknowtheworld Posted January 9, 2007 Share Posted January 9, 2007 [quote author=sloshire1 link=topic=121464.msg500129#msg500129 date=1168297762]How about something like this:<input type="image" src="/images/delete.gif" name="Delete" value="77"><br><input type="image" src="/images/delete.gif" name="Delete" value="78"><br><input type="image" src="/images/delete.gif" name="Delete" value="79"><br>...You would need to create a delete button image, but it would work.[/quote]No same name for all buttons will create problems instead give names as Delete1, Delete2, .... Quote Link to comment Share on other sites More sharing options...
ltbaggz Posted January 10, 2007 Author Share Posted January 10, 2007 if i use input type=button value=uid i have unique entries but then how do i access it when the button is clicked? what should the php read (i know im in the html forum) but i have something like this[code]if(isset($_POST[uid_1])){do something}[/code]so here i check uid_1 now what if uid_2 is clicked? is there a way i can have php account for this and see what is set and access its value? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted January 10, 2007 Share Posted January 10, 2007 can I make a suggestion....don't use a button for each record - use a check box aginst each record and ONE submit button at the bottom of the form...<input type="checkbox" name="delete[]" value="77" /><input type="checkbox" name="delete[]" value="78" /><input type="checkbox" name="delete[]" value="79" />this makes your code in the next page even easier.sice these are checkboxes they only get a value if they are actually checked - otherwise html pretendsw they never existed.In the processing script you can now delete multiple records all with one query like so.[code]<?php$ids = implode(',', $_POST['delete']); // this will make a comma separated string of all the delete checkbox values.$qry = "DELETE FROM `a_table` WHERE `id` IN (" . $ids . ")";$qry = mysql_query($qry);?>[/code] Quote Link to comment Share on other sites More sharing options...
ltbaggz Posted January 10, 2007 Author Share Posted January 10, 2007 Thanks for the input, i was trying to stay away from using checkboxes, i felt buttons fit in the application better. But i may have to resort to it. Thanks for the input i like that little trick with the query. I might just do a link to a page that describes the entry to be deleted, and the user can either edit it or delete it. Have to figure something else out.ThanksDrew Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted January 10, 2007 Share Posted January 10, 2007 Ah I understand. You are wanting to take them to a page that shows what they are about to delete and then confirm.In that case the correct mark-up would simply be a link - not a button. simply place some vars in the url.<a href="/path/to/file/delete.php?record=77" title="Delete Record 77">Delete</a><a href="/path/to/file/delete.php?record=78" title="Delete Record 78">Delete</a><a href="/path/to/file/delete.php?record=79" title="Delete Record 79">Delete</a>Then delete.php can show the stuff and have a confirmation button at the bottom which when pressed will do the delete. Quote Link to comment Share on other sites More sharing options...
ltbaggz Posted January 10, 2007 Author Share Posted January 10, 2007 yeaup that is the route i am taking, originally i wanted to have the delete button right on the page, but thats not going to work out, so im gonna have to do it that way. oh well, it will eventually work one way or another.thanks for the helpdrew Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.