SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Confirm Delete solution - chapter 7 - PHP and MySQL Novice to Ninja

    Dear Kevin,

    Could you post the solution for the "Confirm on Delete" challenge, so I can what I have done is correct.

    Thanks,

    Regards,

    Ronnie

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,881
    Mentioned
    208 Post(s)
    Tagged
    12 Thread(s)
    Hi Ronnie 2013,

    Welcome to the forums.

    There isn't a hard and fast solution to the exercise, so why don't you post what you have coded and ask for feedback.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2009
    Location
    Port Harcourt
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ronnie 2013, you can use a simple javascript to achieve what you want.
    Use this: <input type="submit" name="action" value="Delete" onclick="return confirm('Delete This User?')" />

  4. #4
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, since nobody answered, here is my attempt - which has failed. It says that "$author['id']" on the third line is undefined.


    PHP Code:
    //to confirm and delete an author from the joke databank
    if (isset($_POST['action']) and $_POST['action'] == 'Delete')
    {
        
    $authordeleteid $author['id'];
        include 
    'confirmdeleteauthor.html.php';
        exit();
    }

    if (isset(
    $_POST['connfirmdeleteauthor']))
    {
      include 
    $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';

      
    // Get jokes belonging to author
      
    try
      {
        
    $sql 'SELECT id FROM joke WHERE authorid = :id';
        
    $s $pdo->prepare($sql);
        
    $s->bindValue(':id'$_POST['id']);
        
    $s->execute();
      }
      catch (
    PDOException $e)
      {
        
    $error 'Error getting list of jokes to delete.';
        include 
    'error.html.php';
        exit();
      }

      
    $result $s->fetchAll();

      
    // Delete joke category entries
      
    try
      {
        
    $sql 'DELETE FROM jokecategory WHERE jokeid = :id';
        
    $s $pdo->prepare($sql);

        
    // For each joke
        
    foreach ($result as $row)
        {
          
    $jokeId $row['id'];
          
    $s->bindValue(':id'$jokeId);
          
    $s->execute();
        }
      }
      catch (
    PDOException $e)
      {
        
    $error 'Error deleting category entries for joke.';
        include 
    'error.html.php';
        exit();
      }

      
    // Delete jokes belonging to author
      
    try
      {
        
    $sql 'DELETE FROM joke WHERE authorid = :id';
        
    $s $pdo->prepare($sql);
        
    $s->bindValue(':id'$_POST['id']);
        
    $s->execute();
      }
      catch (
    PDOException $e)
      {
        
    $error 'Error deleting jokes for author.';
        include 
    'error.html.php';
        exit();
      }

      
    // Delete the author
      
    try
      {
        
    $sql 'DELETE FROM author WHERE id = :id';
        
    $s $pdo->prepare($sql);
        
    $s->bindValue(':id'$_POST['id']);
        
    $s->execute();
      }
      catch (
    PDOException $e)
      {
        
    $error 'Error deleting author.';
        include 
    'error.html.php';
        exit();
      }

      
    header('Location: .');
      exit();

    Last edited by cpradio; Jun 27, 2013 at 09:14. Reason: Added php tags

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,066
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    I think you'll want to use $_POST['id'] where you have $author['id'].
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  6. #6
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, that did it! Seems to be other problems with my solution but I'm working my way through it.

  7. #7
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,066
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Great. As you get stuck, don't hesitate to ask us for help. We're more than willing
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes


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
  •