unnormaldude68 Posted June 22, 2009 Share Posted June 22, 2009 Hi, I have a script that calls certain data from tables in my database. I want to be able to delete a specific row from the php page. I have currently added a link in the table that will delete a row when clicked, however, it always deletes the last row and not the one that I want it to delete. Here is the code: <?php $con = mysql_connect('localhost', '****', '****'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("****", $con); $sql="SELECT * from flash"; $result = mysql_query($sql); echo' <HTML> <head> <title>Bans</title> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="table.js"></script> <link rel="stylesheet" type="text/css" href="themes/blue/style.css" /> </head> <body bgcolor="#cccccc"> '; echo' <table id="myTable" class="tablesorter"> <script type="text/javascript"> $(document).ready(function() { $("table").tablesorter({ // sort on the first column and third column, order asc sortList: [[0,0]] }); }); </script> <thead> <tr> <th>ID</th> <th>Moderator</th> <th>User</th> <th>Action</th> <th>Length</th> <th>Date</th> <th>Delete</th> </tr> </thead> '; echo' <tbody>'; if(!isset($cmd)) { while($row = mysql_fetch_array($result)) { $id=$row['id']; echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['moderator'] . "</td>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['action'] . "</td>"; echo "<td>" . $row['length'] . " minutes</td>"; echo "<td>" . $row['date'] . "</td>"; echo "<td><a href='index.php?cmd=delete&id=$id'>Delete</a></td>"; echo "</tr>"; } } if($_GET["cmd"]=="delete") { $sql = "DELETE FROM flash WHERE id=$id"; $result = mysql_query($sql); echo "<meta http-equiv='refresh' content='0; URL=index.php'>"; } echo' </tbody> </table> </body> </HTML>'; ?> Any help would be greatly appreciated. Thanks! Link to comment https://forums.phpfreaks.com/topic/163296-solved-help-with-a-row-delete-script/ Share on other sites More sharing options...
J.Daniels Posted June 22, 2009 Share Posted June 22, 2009 $sql = "DELETE FROM flash WHERE id=$id"; Where are you setting $id? You can echo out $id to check it's value to make sure it is what you are expecting. Link to comment https://forums.phpfreaks.com/topic/163296-solved-help-with-a-row-delete-script/#findComment-861524 Share on other sites More sharing options...
unnormaldude68 Posted June 22, 2009 Author Share Posted June 22, 2009 $id is an auto_increment field in the table. When I hover over the Delete link, &id in the status bar correctly shows the id of the row. So that part is working. Link to comment https://forums.phpfreaks.com/topic/163296-solved-help-with-a-row-delete-script/#findComment-861526 Share on other sites More sharing options...
J.Daniels Posted June 22, 2009 Share Posted June 22, 2009 Is register_globals on?? Try changing $id to $_GET['id'] Link to comment https://forums.phpfreaks.com/topic/163296-solved-help-with-a-row-delete-script/#findComment-861534 Share on other sites More sharing options...
unnormaldude68 Posted June 23, 2009 Author Share Posted June 23, 2009 Thank you very much for your help. I got it to work Link to comment https://forums.phpfreaks.com/topic/163296-solved-help-with-a-row-delete-script/#findComment-861655 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.