Jump to content

[SOLVED] Help with a row delete script.


unnormaldude68

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.