Deleting a Record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jonborbon
    New Member
    • Sep 2006
    • 5

    Deleting a Record

    Hi All!

    I have a form (form1.php) that displays the contents of a table, alongside each row is an icon to delete or edit that record. If I click on the 'delete' icon, the record number should be passed to another page (lets say 'processor.php' ) which has a lot of functions one of which is the 'eraseit' function.

    My problem is that the record is not deleted with this code snippets:

    <a href='process.p hp?action='POST '&id='eraseit '>

    I'm new to PHP programming and I would appreciate all the help. Thanks in advance.

    MRB
  • steven
    New Member
    • Sep 2006
    • 143

    #2
    "<a href='process.p hp?action='POST '&id='eraseit'> "

    I don't know why you have the action=POST, seeing as selecting the link will still display the information in the address bar. Remove that.

    Also, I don't think you're passing in any specific information to the PHP. How does the PHP know which record to delete?

    You should have your function eraseit in the PHP and then that should check for input. Eg,

    Code:
    <a href="process.php?id=NUMERICAL ID OF RECORD&delete=1">
    
    if (isset ($_GET['id']) && isset ($_GET['delete']) && $_GET['id']) {
        // SQL Statement, delete from x where id = $_GET['id']
    }
    Really basic, but it's difficult to give you a definitive answer without seeing your code and the exact function you're trying to do.

    Comment

    • jonborbon
      New Member
      • Sep 2006
      • 5

      #3
      Steven,

      First, thanks for the reply. I really appreciate the help.

      The contents of 'processor.php' looks like this:
      Code:
      <?php
      include("../include/session.php");
      class AdminProcess
      {
        function eraseit(){
            global $session, $database, $form;
            $subuser = $this->checkUsername("deluser"); //del
            $q = "DELETE FROM ".TBL_USERS." WHERE username = '$subuser'";
            $database->query($q);
            header("Location: form1.php");
      
         function checkUsername($uname, $ban=false){
            global $database, $form;
            $subuser = $_POST[$uname];
             <some error checking codes>
             return $subuser;
      
      
      }

      Comment

      • jonborbon
        New Member
        • Sep 2006
        • 5

        #4
        Steven,

        First, thanks for the reply. I really appreciate the help.

        The contents of 'processor.php' looks like this:
        Code:
        <?php
        include("../include/session.php");
        class AdminProcess
        {
          function eraseit(){
              global $session, $database, $form;
              $subuser = $this->checkUsername("deluser"); //deluser is the image name
                 :
              $q = "DELETE FROM ".TBL_USERS." WHERE username = '$subuser'";
              $database->query($q);
              header("Location: form1.php");
        
           function checkUsername($uname){ 
              global $database, $form;
              $subuser = $_POST[$uname];
               <......some error checking codes>
               return $subuser;
             }
             function N()
        }
        What I intend to accomplish is to let PROCESSOR.php do all the necessary check and record activities like deletion and then return the output to FORM1.php.

        Again, thanks.

        Comment

        Working...