SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Novice to Ninja - Chapter 7 "Confirm on Delete"

    Hi Guys, I've been working my way through this book and up until this point its been pretty straight forward. There is an optional task to make the user confirm you want to delete the author in this chapter and I got stuck for the past hour trying to get it to work.

    I'm wondering if someone can point out what I have done wrong here, everything works if I remove my extra code to confirm the action.


    Index Page
    PHP Code:
    if (isset($_POST['action']) and $_POST['action'] == 'Delete')
    {
        include 
    'confirm.delete.php';
        exit();
    }
    if (isset(
    $_POST['action']) and $_POST['action'] == 'Unconfirmed')
    {
        include 
    'authors.html.php'
        
    exit();
    }
    if (isset(
    $_POST['action']) and $_POST['action'] == 'Confirmed')
    {    
        try
        {  ...
    code that deletes user is here 
    Confirm Delete HTML(confirm.delete.php)
    PHP Code:
    <?php include_once $_SERVER['DOCUMENT_ROOT'] . '/phpnin/includes/helpers.inc.php'?>
    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8">
            <title>Confirm Author Deletion</title>
        </head>
        <body>
            <h1>Manage Authors</h1>
            <p>Are you sure you want to delete author <?php htmlout($_POST['name']); ?>?</p>
                    <form action=" " method="post">
                        <div>
                            <input type="hidden" name="id" value="<?php echo ($_POST['id']); ?>">
                            <input type="submit" action="action" value="Confirmed">
                            <input type="submit" action="action" value="Unconfirmed">
                        </div>
                    </form>
    </body>
    </html>

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,995
    Mentioned
    100 Post(s)
    Tagged
    0 Thread(s)
    What error if any are you getting when you're trying your code?

    Have a read of the manual page about exceptions (just in case you've got the syntax wrong)
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply.. I'm not getting an error, it simply seems like the if statements for "Confirm" and "Uncofirm" aren't executing, it just returns to the main page. I tried getting them to echo some text but the only one that works is the "Delete" button which is included in the index.php file from another file called "authors.html.php" --
    PHP Code:
        <?php foreach ($authors as $author): ?>
                <li>
                    <form action=" " method="post">
                        <div>
                            <?php htmlout($author['name']); ?>
                            <input type="hidden" name="id" value="<?php echo ($author['id']); ?>">
                            <input type="hidden" name="name" value="<?php echo ($author['name']); ?>">
                            <br/>
                            <input type="submit" name="action" value="Edit">
                            <input type="submit" name="action" value="Delete">
                        </div>
                    </form>
                </li>
                <?php endforeach; ?>


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
  •