title: Why can't I delete data with this code?
body: <p>I wrote a notebook with php and xampp, somehow my delete function is not working can anybody find out the problem?</p>
  
  <pre><code>admin   %   global  ALL PRIVILEGES  Yes     Edit Privileges Edit Privileges
  database-specific   ALL PRIVILEGES  No  Edit Privileges Edit Privileges
  admin   localhost   global  ALL PRIVILEGES  Yes     Edit Privileges Edit Privileges
  database-specific   ALL PRIVILEGES  No  Edit Privileges Edit Privileges
  root    127.0.0.1   global  ALL PRIVILEGES  Yes     Edit Privileges Edit Privileges
  root    localhost   global  ALL PRIVILEGES  Yes     Edit Privileges Edit Privileges
  
   ALTER TABLE `note` CHANGE `id` `id` INT( 100 ) NOT NULL AUTO_INCREMENT ,
  CHANGE `topic` `topic` VARCHAR( 1000 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL ,
  CHANGE `topicoutline` `topicoutline` VARCHAR( 2000 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL ,
  CHANGE `timestamp` `timestamp` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00'
  </code></pre>
  
  <p>
  </p>
  
  <pre><code>  &lt;?php
      $userName = "admin";
      $password = "admin";
      $hostname = "localhost";
      $databaseName = "notebook";
      $tableName = "note";
      $myDB = mysql_connect("localhost", $userName, $password);
  
  if ($myDB) { print "Database Connect succeeded&lt;p&gt;"; }
  else { print "Database Connect failed&lt;p&gt;"; die(1);}
  
  //connect and astart using the database
  
  $status = mysql_select_db($databaseName, $myDB);
  if ($status) 
  { echo "Select Database $databaseName succeeded&lt;p&gt;"; }
  else 
  { echo "Select Database $databaseName failed&lt;p&gt;";}
  
  #$result = mysql_query('Select * from note', $myDB );
  
   #while ($row = mysql_fetch_row($result)) {
  
      #echo $row[0] . ", "; #display results
      #echo $row[1] . ", ";
      #echo $row[2] . ", ";
      #echo $row[3] . "&lt;p&gt;";
  #}
  #mysql_free_result($result); # release memory
  #mysql_close($myDB);
  
    function AddTopic() {
        global $myDB, $this_script;
  
        if (isset ($_POST['topic']))
        $topic = $_POST['topic'];
        else 
        return;
  
        if (isset ($_POST['topicoutline']))
        $topicoutline = $_POST['topicoutline'];
        else 
        return;
  
        if($topic == "" || $topicoutline == "")
        return;
  
  
  
        $query = "insert into note (topic, topicoutline, timestamp) values('$topic', '$topicoutline', now());";
        $result = mysql_query($query, $myDB);
  
        if (!$result) mysql_error($myDB);
        else header("Location: $this_script"); #redirect to Show all
        }
  
    function ShowAll() {
         global $myDB;
        $query="Select * from note;";
        $result = mysql_query($query, $myDB );
      while ($row = mysql_fetch_object($result)) {
      echo $row-&gt;id . "&lt;br&gt;";
      echo $row-&gt;topic . "&lt;br&gt;";
      echo $row-&gt;topicoutline . "&lt;br&gt;";
      echo $row-&gt;timestamp . "&lt;p&gt;";
      }       
  
       mysql_free_result($result);
      }
  
      function td($item){
      return "&lt;td&gt;$item&lt;/td&gt;\n";
      }
  
      function linktodelete($url, $prompt){
  
      return "&lt;a href = '$url'&gt;$prompt&lt;/a&gt;";
  
      }
  
      function FrontPage() {
  
         global $myDB, $this_script;
         deleteTopic();
         AddTopic();
  
      if (isset($_REQUEST['findthis'])) 
      $where = $_REQUEST['findthis'];
      else $where = '';
      $query = 'Select * from note';
      if ($where) 
      $query = $query . " where topic like '%$where%' or topicoutline like '%$where%'";
      $query = $query .";" ;
      $result = mysql_query($query, $myDB );
      print "&lt;table border='1' bgcolor='#AADDFF' width='80%'&gt;\n";
  
      print "&lt;tr&gt;&lt;td&gt;id&lt;/td&gt; &lt;td&gt;topic&lt;/td&gt; &lt;td&gt;topicoutline&lt;/td&gt; &lt;td&gt;timestamp&lt;/td&gt;&lt;/tr&gt; \n";
  
      while ($row =mysql_fetch_object($result)) {
      $id = $row-&gt;id;
      print "&lt;tr&gt;";
  
      print td($row-&gt;id). td($row-&gt;topic). td($row-&gt;topicoutline). td($row-&gt;timestamp). td(linktodelete($this_script . "?cmd=del&amp;id=$id","Delete"));
      print "&lt;/tr&gt;\n";
  
      }
  
      print "&lt;table&gt;\n";
      mysql_free_result($result);
  
      print DisplayFindForm();
      print DisplayNameAdditionForm();
      }
    //showAll();
  
    function deleteTopic() {
    global $myDB, $this_script;
    if (isset($_REQUEST['$id']))
      $id = $_REQUEST['id'];
      else
      $id = '';
      $query = "delete from note where id='$id';";
      $result = mysql_query($query, $myDB);
    if (!$result) mysql_error($myDB);
    else header("Location: $this_script");
    }
  
      function DisplayNameAdditionForm() {
      global $this_script;
      print "
      &lt;hr&gt;
      &lt;form method='POST' action='$this_script'&gt;
      &lt;input type='hidden' name='cmd' value='add'&gt;
      topic &lt;input type='text' name='topic' size='100'&gt;
      topicoutline &lt;input type='text' name='topicoutline' size='100'&gt;
      &lt;input type='submit' value=' Add ' name='B1'&gt;
      &lt;/form&gt;
      ";
      }
  
  
      function DisplayFindForm() {
      global $this_script;
      print "
      &lt;hr&gt;
      &lt;form method='POST' action='$this_script'&gt;
      &lt;input type='hidden' name = 'cmd' value='find'&gt;
      &lt;input type='text' name = 'findthis' size='20'&gt;
      &lt;input type='submit' value=' Find name ' name='B1'&gt;
      &lt;/form&gt;
      ";
      }
  
    FrontPage();
  
    ?&gt;
  </code></pre>
  
  <p>
  </p>