sh0wtym3 Posted September 26, 2008 Share Posted September 26, 2008 I want to add a "delete this file" link under each result from my query. (I dont want it to delete an actual file, just the row in the database). When you click the link it says "file deleted!", but it doesn't delete the row. Below is my attempt at making it work. Once again thanks in advance. { echo "You have uploaded a total of <b>$num_rows</b> files.<br><br><br>"; } //Loop through the result set while($row = mysql_fetch_assoc($rs)) { print "<u>File Title</u> : <b>{$row['title']}</b> <br>"; print "File Size : "; print ByteSize($row['filesize']); print "<br>"; print "<a href=\"?cmd=delete&id={$row['ID']}\">Delete this file</a><br><br>"; } $id = "{$row['ID']}"; if($_GET["cmd"]=="delete") { $sql = "DELETE FROM table WHERE ID = $id"; $result = mysql_query($sql); echo "<b>File deleted!</b><br>"; } //Display the navigation " . $id . " echo $pager->renderFullNav(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/125879-solved-deleting-a-row/ Share on other sites More sharing options...
redarrow Posted September 26, 2008 Share Posted September 26, 2008 print "<a href=\"?cmd=delete&id={$row['ID']}\">Delete this file</a><br><br>"; where the page it going to, to delete........ maybe $_SERVER['PHP_SELF'] might help and your getting the id from a url $sql = "DELETE FROM table WHERE ID = ".$_GET['$id']." "; Quote Link to comment https://forums.phpfreaks.com/topic/125879-solved-deleting-a-row/#findComment-650916 Share on other sites More sharing options...
dropfaith Posted September 26, 2008 Share Posted September 26, 2008 heres a nice easy delete script conf.php is your host details and pass <?php // includes include("../template/conf.php"); // open database connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // generate and execute query $Id = mysql_escape_string($_GET['Id']); mysql_query("DELETE FROM Events WHERE Id = '$Id'") or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/125879-solved-deleting-a-row/#findComment-650917 Share on other sites More sharing options...
sh0wtym3 Posted September 26, 2008 Author Share Posted September 26, 2008 I ended up using: $sql = "DELETE FROM beats WHERE ID = ".$_GET['id']." "; I also added a quick script to refresh the page too, works like a charm. Thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/125879-solved-deleting-a-row/#findComment-650929 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.