PHP Issue with deleting from MySQL
<p>I do have programming experience, but new to php. I do have an issue with an example I was doing from this tutorial. I looked over it millions of times, googled, ect ect. I don't have an idea why my code isnt working. </p>

<p>The purpose is to basically just test inserting and deleting in sql from php, using a button for Add Record and Delete Record. The Add record button works perfectly, but delete doesnt do a thing other than reload the page. Heres the code...</p>

<pre><code>&lt;?php // sqltest.php

require_once 'login.php';

$db_server = mysql_connect($db_hostname, $db_username, $db_password);

if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());

mysql_select_db($db_database, $db_server)
     or die("Unable to select database: " . mysql_error());

if (isset($_POST['author'])   &amp;&amp;
    isset($_POST['title'])    &amp;&amp;
    isset($_POST['type'])     &amp;&amp;
    isset($_POST['year'])      &amp;&amp;
    isset($_POST['isbn']))
{
    $author = get_post('author');
    $title = get_post('title');
    $type = get_post('type');
    $year = get_post('year');
    $isbn = get_post('isbn');

    if (isset($_POST['delete']) &amp;&amp; $isbn != "")
    {
        echo "worked!!!!!!!!!!!!!!"; 
        $query = "DELETE FROM classics WHERE isbn='$isbn'";
        $result = mysql_query($query) or die(mysql_error());
        if(mysql_affected_rows($result) &gt; 0) echo 'user deleted';

        //if (!mysql_query($query, $db_server))
        //echo "DELETE failed: $query" . mysql_error();
    }
    else
    {
        echo "nooooooooooooooooooo";
        $query = "INSERT INTO classics VALUES" .
        "('$author', '$title', '$type', '$year', '$isbn')";
        if (!mysql_query($query, $db_server)) 
        {
            echo "INSERT failed: $query" . mysql_error();
        }
    }
}

echo &lt;&lt;&lt;_END
&lt;form action="sqltest.php" method="post"&gt;&lt;pre&gt;
Author &lt;input type="text" name="author" /&gt;
Title  &lt;input type="text" name="title" /&gt;
Type   &lt;input type="text" name="type" /&gt;
Year   &lt;input type="text" name="year" /&gt;
ISBN   &lt;input type="text" name="isbn" /&gt;
&lt;input type='submit' value='ADD RECORD' /&gt;
&lt;/pre&gt;&lt;/form&gt;
_END;



$query = "SELECT * FROM classics";

$result = mysql_query($query);

if (!$result) die ("Database access failed: " . mysql_error());

$rows = mysql_num_rows($result);

for ($j = 0 ; $j &lt; $rows ; ++$j)
{
        $row = mysql_fetch_row($result);

echo &lt;&lt;&lt;_END
&lt;pre&gt;
Author $row[0]
Title $row[1]
Type $row[2]
Year $row[3]
ISBN $row[4]
&lt;form action="sqltest.php" method="post"&gt;
&lt;input type="hidden" name="delete" value="yes" /&gt;
&lt;input type="hidden" name='isbn' value="$row[4]" /&gt;
&lt;input type='submit' value='DELETE RECORD' /&gt;
&lt;/form&gt;
&lt;/pre&gt;
_END;
}

mysql_close($db_server);

function get_post($var)
{
    return mysql_real_escape_string($_POST[$var]);
}

?&gt;
</code></pre>

<p>I have looked over this many times, still no idea why this won't work. Is it the for loop that is making this button not work? Note, you will see echo "worked!!!"; and in the else echo "noooooooo"; that was for me to test whether the button was being tested, yet nothing prints. So maybe i missed something in the button code itself? Also, no errors are printed, and my editor (and myself) have missed the syntax error (if thats the case).</p>

<p>The code for the delete button is at the end, before I closed the DB.</p>

<p>Thanks for your help in advance.</p>
