faisalabad Posted April 18, 2010 Share Posted April 18, 2010 HI everyone .. a newbe to php i am accessing a table and assinging it to a associate array and with wile loop printing it as table, at the end of every row i have delete button (also part of the while loop )..... what i want to do is for user to be able Click any "delete" and corrosponding row get deleted from database and then reprint the new updated table... at the moment it seams only the first "delete" button respond, even that does not delete any record from data base .... help please i am stuck for last 4 days and new to php and programming ... here is the code that print the table and delete buttons <?php if ($_POST['delete']) { $cattodel = $_POST['cat_id']; mysql_query("DELETE FROM catalogue WHERE cat_id ='$cattodel'"); } mysql_connect('localhost','root','root'); mysql_select_db('Catalogues'); $getdata = mysql_query("SELECT * FROM catalogue"); echo " <table border='1'> <tr> <td>Catalogue number</td> <td>Catalogue name</td> <td>File name</td> <td>Sale setup</td> <td>Arrival date </td> <td>Copy & Retails links</td> <td>Images & Catalogues pages</td> <td>Due date</td> <td>Status</td> </tr> <form action='viewcatalogues.php' method='post' enctype='multipart/form-data'>"; while($data = mysql_fetch_assoc($getdata)) { echo " <tr> <td>".$data['cat_id']."</td> <td>".$data['catalogue_name']."</td> <td>".$data['file_name']."</td> <td><a href='".$data['sale_setup']."'>".$data['sale_setup']."</a></td> <td>".$data['arrival']."</td> <td>".$data['copy_retail']."</td> <td>".$data['image_cata']."</td> <td>".$data['due']."</td> <td>".$data['status']."</td> <td><input type='submit' name='delete' ></td> </tr> </form>"; } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/198901-mutiple-instance-of-same-delete-buttong/ Share on other sites More sharing options...
-Karl- Posted April 18, 2010 Share Posted April 18, 2010 if isset($_POST['delete']) You'll also need to POST the cat_id <input type="hidden" name="cat_id" value="{$data['cat_id']}"> Link to comment https://forums.phpfreaks.com/topic/198901-mutiple-instance-of-same-delete-buttong/#findComment-1044058 Share on other sites More sharing options...
faisalabad Posted April 18, 2010 Author Share Posted April 18, 2010 Thanks Karl .... thank you so much .... its working now ;D ;D ;D Link to comment https://forums.phpfreaks.com/topic/198901-mutiple-instance-of-same-delete-buttong/#findComment-1044066 Share on other sites More sharing options...
-Karl- Posted April 18, 2010 Share Posted April 18, 2010 You're welcome sir, can you click the "Mark Solved" button at the bottom of the thread? Link to comment https://forums.phpfreaks.com/topic/198901-mutiple-instance-of-same-delete-buttong/#findComment-1044071 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.