SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    Not Bad, eh? Justin Sampson's Avatar
    Join Date
    Aug 2000
    Location
    N.S., Canada
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Can Anyone tell me whats wrong with this script? I'm trying to get it so when you go to http://www.domain.com/delete.php3?id=2 it will delete the article with the ID of 2 when you click the button. Here's the code I have. It doesn't give me any errors but it doesn't do anything either

    Code:
    <?php
     
      if ("SUBMIT" == $deletearticle) {
       $sql = "DELETE FROM articles WHERE ID=$id ";
       
       if (mysql_query($sql)) {
       echo("<P>Your article has been deleted.</P>");     
        } else {    
    	echo("<P>Error deleting article: " .
    mysql_error() . "</P>");      
    }
    }
    ?>
    <form ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
    <INPUT TYPE=HIDDEN NAME="id" VALUE="<?php echo($id); ?>">
    <INPUT TYPE=SUBMIT NAME="deletearticle" VALUE="Delete">
    </form>
    Thanks,
    Justin Sampson

  2. #2
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?php

    if ("Delete" == $deletearticle) {
    $sql = "DELETE FROM articles WHERE ID=$id ";

    if (mysql_query($sql)) {
    echo("<P>Your article has been deleted.</P>");
    } else {
    echo("<P>Error deleting article: " .
    mysql_error() . "</P>");
    }
    }
    ?>
    <form ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
    <INPUT TYPE=HIDDEN NAME="id" VALUE="<?php echo($id); ?>">
    <INPUT TYPE=SUBMIT NAME="deletearticle" VALUE="Delete">
    </form>

    This should do the job for you.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And to elaborate but not to discount Karl's great advice the reaon is the name of your submit button was set to "deletearticle" and you were checking if it was equal to "SUBMIT"
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was just a bit brief wasn't I? I was sorting out a little mistake for another member at the time and it was a bit on the urgent side.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And I guess I was in the same boat because he should be checking for if ($deletearticle == "Delete")
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    Not Bad, eh? Justin Sampson's Avatar
    Join Date
    Aug 2000
    Location
    N.S., Canada
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That works great! Thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •