SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Nov 2004
    Location
    London
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Page 109 of Kevin Yank's PHP/MySQL book

    Hi,

    On page 109 there's an exercise of adding a confirmation prompt to the deleteauthor.php page.

    I've been trying to do this exercise but haven't succeeded because:

    1) I don't fully understand the author's explanation of $_SERVER['PHP_SELF'].
    2) The PHP syntax is really confusing (especially the quotation marks).

    Did anyone do this exercise, and if you did, how did you do it please?


  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    show the piece of code...
    my book hasnt arrived yet

  3. #3
    SitePoint Member
    Join Date
    Nov 2004
    Location
    London
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Joke CMS: Delete Author</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <?php

    $dbcnx = mysql_connect('localhost', 'root', 'mypassword');
    if (!$dbcnx) {
    exit('<p>Unable to connect to the database server at this time.</p>');
    }

    if (!@mysql_select_db('ijdb')) {
    exit('<p>Unable to locate the joke database at this time.</p>');
    }

    // Delete all jokes belonging to the author along with the entry for the author.
    $id = $_GET['id'];
    $ok1 = @mysql_query("DELETE FROM joke WHERE authorid='$id'");
    $ok2 = @mysql_query("DELETE FROM author WHERE id='$id'");
    if ($ok1 and $ok2) {
    echo '<p>Author deleted successfully!</p>';
    } else {
    echo '<p>Error deleting author from database!<br />' .
    'Error: ' . mysql_error() . '</p>';
    }
    ?>
    <p><a href="authors.php">Return to authors list</a></p>
    </body>
    </html>

  4. #4
    SitePoint Member
    Join Date
    Nov 2004
    Location
    London
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the original code in the book. The user clicks on a delete link from another page (authors.php), and the author is immediately deleted. I've been trying to use an if else statement to bring up a prompt which asks the user to confirm the deletion before the author's name is deleted.

  5. #5
    SitePoint Member
    Join Date
    Nov 2004
    Location
    London
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the code for authors.php:

    <body>
    <h1>Manage Authors</h1>
    <ul>
    <?php

    $dbcnx = @mysql_connect('localhost', 'root', 'mypassword');
    if (!$dbcnx) {
    exit('<p>Unable to connect to the database server at this time.</p>');
    }

    if (!@mysql_select_db('ijdb')) {
    exit('<p>Unable to locate the joke database at this time.</p>');
    }

    $author_list = mysql_query('SELECT id, name FROM author');
    if (!$author_list) {
    exit('<p>Error retrieving authors from database!<br />'.
    'Error: ' . mysql_error() . '</p>');
    }

    while ($author = mysql_fetch_array($author_list)) {
    $id = $author['id'];
    $name = htmlspecialchars($author['name']);
    echo "<li>$name " .
    "<a href='editauthor.php?id=$id'>Edit</a> " .
    "<a href='deleteauthor3.php?id=$id'>Delete</a></li>";
    }
    ?>
    </ul>
    <p><a href="newauthor.php">Add a new author</a></p>
    <p><a href="index.html">Return to front page</a></p>
    </body>
    </html>

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where u see here server php self?
    what is wrong in this code?
    regards


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
  •