multiple instance of same 'delete ' button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • faisalabad
    New Member
    • Apr 2010
    • 1

    multiple instance of same 'delete ' button

    Hi everyone
    newb, i am connecting to database then accessing a table and printing whole table on php page as table with "delete" button at the end of every row (so same delete button being printed many times).
    want i want to do is if a user to be able to click on any delete button and that row data get deleted from database and reload the page with updated table.
    i can print the table with data and "delete " button at the end but only first button works, but no data being passed so the delete query does not work ..
    all the other buttons you can press but they do not respond
    here is codes for printing form and table


    Code:
    <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' value='del' ></td>
    		</tr>";
    	echo "
    	</form>";

    please help
    Last edited by Atli; Apr 16 '10, 11:08 PM. Reason: Added [code] tags.
  • nouras
    New Member
    • Apr 2010
    • 15

    #2
    you can send the id of row which you want to delete
    like this ::
    Code:
    <?
    $query = $db->query("SELECT * FROM ".$base." ");
    
    	        if($db->num($query)){           
                    
                    while ($result = $db->fetch($query)){
                      
               echo '<tr>
                            <td>'.$result[title_en].'</td>
    	                    <td><a href="'.$url.'&act=del&id='.$result[id].'">Delete</a></td>';
    
                        
    	                    
                       echo'</tr>';
    	            }
                   
    	}
    
    ?>

    Comment

    Working...