I have the following code in a page of mine, and for some reason it doesn't delete from the database, but if I run the query direclty in MySQL Front it does work.

I have ripped all the stuff out that doesn't matter to this query and so it's easier to see.

If it's any help, the $id is an auto_increment number


Many Thanks
Ian Gunter


PHP Code:
<?
//uploader.php
function delete_file() {
?><table width="615" border="0" cellspacing="2" cellpadding="2">
        <tr>
            <td><p><strong>File Deleted</strong></p></td>
        </tr><tr>
            <td><hr color='#333333' size='1'></td>
        </tr>
        </table>
        <?
        // create SQL statement
        $sql = "DELETE FROM files WHERE id=$id";

        $results = mysql_query($sql);

        index();
}
function index() {
?><table width="615" border="0" cellspacing="2" cellpadding="2">
        <tr>
            <td width='**'><p><strong>Filename</strong></p></td>
            <td width='55' align="center" colspan="3"><p><strong>actions</strong></p></td>
        </tr><tr>
            <td colspan='2'><hr color='#333333' size='1'></td>
        </tr><?
        // create SQL statement
        $sql = "SELECT * FROM files";

        // execute SQL query and get result
        $sql_result = mysql_query($sql)
            or die("Couldn't execute query.");

        // format results by row
        while ($row = mysql_fetch_array($sql_result)) {
            $id = $row["id"];
            $filename = $row["filename"];

        // format html output
        echo "<tr>
            <td width='**'>$filename</td>
            <td width='55' align='center'><a href=\"?action=delete&id=$id\" onclick=\"return confirm('Are you sure you wish to delete this file?')\"><img src='images/but-delete.gif' width='50' height='15' border='0'></a></td>
        </tr>";
        }
        ?><tr>
            <td colspan='2'><hr color='#333333' size='1'></td>
        </tr><tr>
            <td width='**'><p></p></td>
            <td width='55' align='center'><a href='?action=add'><img src='images/but-add.gif' width='50' height='15' border='0'></a></td>
        </tr>
        </table>
<? require('auth.inc'); ?>
<html>
<head>
    <title>Mando Group - Control-C</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="styles/control_c.css" rel="stylesheet" type="text/css">
</head>

<body>

<? include ('../includes/connect.inc'); ?>

<table width="738" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
    <td><strong>Downloads</strong><br>
        <span class="textsmall">Add a new download</span></td>
</tr><tr>
    <td align="center"><?
        if($action == 'upload') upload_file();
        else if($action == 'add') upload_form();
        else if($action == 'delete') delete_file();
        else index();
    ?></td>
</tr>
</table>
</body>
</html>