SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Addict DM3Dan's Avatar
    Join Date
    Sep 2004
    Location
    Albany, NY
    Posts
    204
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Deleting blog entry

    I have a link going to 'deletepost.php' from my admin page. There is a link such as this:
    example.com/deletepost.php?postID=8
    However, when I click that link, I always get my 'Deletion Failed' message. Any ideas?

    Deletepost.php:
    PHP Code:
    <?php
    include 'top.php';

    $postID $_GET['postID']; 
    $postID intval($_GET['postid']);
    $delete "DELETE * FROM posttbl WHERE postID=$postID";


    $dbcnx mysql_connect("localhost""****""****"); 
    mysql_select_db("****");

        if(!isset(
    $_SESSION['authorized']))
        {
            
    header('Location: login.php');
        }

    $delete mysql_query($delete);

        if(
    $delete)
        {
            
    header('Location: index.php');
        }

        else
        {
            exit(
    'Deletion failed');
        }
        echo 
    mysql_error();

    ?>

  2. #2
    SitePoint Guru gavwvin's Avatar
    Join Date
    Nov 2004
    Location
    Cornwall, UK
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    after this line:
    PHP Code:
    $delete mysql_query($delete); 
    put this line
    PHP Code:
    echo mysql_error(); 
    That should tell you the problem with your query

  3. #3
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shouldn't

    $postID = intval($_GET['postid']);

    Be

    $postID = intval($_GET['postID']);

  4. #4
    SitePoint Addict DM3Dan's Avatar
    Join Date
    Sep 2004
    Location
    Albany, NY
    Posts
    204
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gavwvin
    after this line:
    PHP Code:
    $delete mysql_query($delete); 
    put this line
    PHP Code:
    echo mysql_error(); 
    That should tell you the problem with your query
    Code:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM posttbl WHERE postID=0' at line 1Deletion failed
    AKA, postID isn't being carried from my link. I geuss I can't just put ?postID=8 at the end of my URL and expect it to carry that over as postID

  5. #5
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $delete = "DELETE FROM posttbl WHERE postID=$postID";

    You don't need the wildcard for deletion queries, I don't think.

  6. #6
    SitePoint Addict DM3Dan's Avatar
    Join Date
    Sep 2004
    Location
    Albany, NY
    Posts
    204
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, now it just redirects me to index.php, without deleting the post.

    Here is my admin page(Well, the part that relates to this).

    PHP Code:
    <?php
    $allposts 
    "SELECT * FROM posttbl";

    $allposts mysql_query($allposts);
    echo 
    '<table>';

    while(
    $row mysql_fetch_array($allposts))
    {
    $ID $row['postID'];
    echo<<<EOV
    <tr style="font-size:80%"><td style="padding:5px">
    <a href="viewposts.php?postID=
    {$ID}">{$row['postTITLE']}</a></td>
    <td><a href="editpost.php?postID=
    {$ID}"> Edit</a>/
    <a href="deletepost.php?postID=
    {$ID}"> Delete</tr>
    EOV;
    }
    ?>

  7. #7
    SitePoint Guru gavwvin's Avatar
    Join Date
    Nov 2004
    Location
    Cornwall, UK
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Theres your problem:
    PHP Code:
    $postID intval($_GET['postid']); 
    should be
    PHP Code:
    $postID intval($_GET['postID']); 

  8. #8
    SitePoint Addict DM3Dan's Avatar
    Join Date
    Sep 2004
    Location
    Albany, NY
    Posts
    204
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    GAH!

    Nice catch, it works now .

  9. #9
    SitePoint Wizard Young Twig's Avatar
    Join Date
    Dec 2003
    Location
    Albany, New York
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DM3Dan
    PHP Code:
    $postID $_GET['postID']; 
    $postID intval($_GET['postid']); 
    Why, Daniel, why?

  10. #10
    SitePoint Addict DM3Dan's Avatar
    Join Date
    Sep 2004
    Location
    Albany, NY
    Posts
    204
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I fixed it now. And you coded that part in advisory, retard.

  11. #11
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Isn't that what I suggested?

  12. #12
    SitePoint Wizard Young Twig's Avatar
    Join Date
    Dec 2003
    Location
    Albany, New York
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DM3Dan
    I fixed it now. And you coded that part in advisory, retard.
    I did not write that.

    Edit:

    Oh, and Dan... let this be a lesson: capital letters suck.

  13. #13
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:


    Mr. Hehir, where have you been lately?

  14. #14
    SitePoint Wizard Young Twig's Avatar
    Join Date
    Dec 2003
    Location
    Albany, New York
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    MSN's off, huh? I'll get on.

  15. #15
    SitePoint Addict DM3Dan's Avatar
    Join Date
    Sep 2004
    Location
    Albany, NY
    Posts
    204
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Young Twig
    Edit:

    Oh, and Dan... let this be a lesson: capital letters suck.
    Not me... Dav. I use lowers, except in functions.


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
  •