Hi, Im using this to display the content of the sql table. <?php include ("config.php"); $result = mysql_query("SELECT * FROM footer"); while($row = mysql_fetch_array($result)) { echo "<a href='{$row['url']}'>{$row['anchor']}</a><br /><br />"; } ?> PHP: This works fine but I need to know how to delete a specific result it out puts. I.e have a delete button next to each result ! Hope that is clear.
Let me tell you a simple Logic: put a hyperlink on a delete button and pass that row['url'] and row['anchor'] to another page say deletefooter.php. Now on deletefooter.php page, fire following query. Hope this helps..
Always always always always filter your input. Specially when it's being placed directly in DELETE queries. www.php.net/mysql_real_escape_string www.php.net/intval
Try this: <?php include ("config.php"); if(isset($_GET['delete_anchor'])){ $sql = mysql_query('DELETE FROM `footer` WHERE `anchor` = "'.$_GET['anchor'].'" AND `url` = "'.$_GET['url'].'"'); if($sql) echo 'Record deleted.<br/><br/>'; else echo '<font color="red">Could not delete a record.</font><br/><br/>'; } $result = mysql_query("SELECT * FROM footer"); while($row = mysql_fetch_array($result)) { echo "<a href='{$row['url']}'>{$row['anchor']}</a>"; $url = '?delete_anchor='.$row['anchor'].'&delete_url='.$row['url']; $message = 'Are you sure?'; echo '<input type="button" onclick="javascript:confirm_delete(\''.$url.'\',\''.$mess.'\')" value="Delete"/><br /><br />'; } ?> PHP: Also put the JavaScript code to ask for confirmation before deleting: <script> function confirm_delete(url,message){ if(confirm(message)){ window.location.href = url; } } </script> Code (markup): I always have an AUTO_INCREMENT field `id` in each table. It's unique, so can use it in such cases - only one parameter needs to be passed. And BTW, note that I personally prefere single quotes in strings - that way code is more readable IMHO as you can better destinguish variables from strings.
Thanks. It kinda works but doesnt delete the resource, also there is no message on the javascript warning.