SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,376
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    CMS section of Database book

    I typed up the CMS scripts in the Database book (c) 2004. I used my list of countries rather than your list of authors. I left out the email list also. Everything else stayed the same.

    The country.php page gave me a list of the countries with Edit and Delete next to them.
    The deletecountry.php page worked well.
    The newcountry.php also worked.

    But when I click on Edit next to a country name in the country.php page, the editcountry.php page comes up with this on the page (on a blank white screen):

    Parse error: syntax error, unexpected T_ELSE in C:\wamp\www\editcountry.php on line 43

    Line 43 of the code in editcountry.php is:

    PHP Code:
    else: /*Allow the user to edit the country*/ 
    This is the code in the editcountry.php page. I can’t find any reason for the error:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>Edit Country, pp 113-115 Yank book</title>
    <link rel="stylesheet" type="text/css" href="../css/associatedcss.css" />
    </head>
    <body>
    <?php

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

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

    if (isset(
    $_POST['category']));
    /*The country's details have been updated.*/

    $category $_POST['category'];
    $id $_POST['id'];
    $sql "UPDATE country SET
            category='
    $category',
            WHERE id='
    $id'";
    if (@
    mysql_query($sql)) {
    echo 
    '<p>Country details updated.</p>';
    } else {
    echo 
    '<p>Error updating country details: ' .
            
    mysql_error() . '</p>';
    }

    ?>

    <p><a href="country.php">Return to country list</a></p>

    <?php
    else: /* Allow the user to edit the country*/

    $id $_GET['id'];
    $country = @mysql_query(
            
    "SELECT category FROM country WHERE id='$id'");
    if(!
    $country) {
        exit(
    '<p>Error fetching country details: ' .
            
    mysql_error() . '</p>');
    }

    $country mysql_fetch_array($country);

    $category $country['category'];

    /* Convert special characters for safe use as HTML attributes */
    $category htmlspecialchars($category);

    ?>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <p>Edit the country:</p>
    <label>Country: <input type="text" name="category"
        value="<?php echo $category?>" /></label><br />
    <input type="hidden" name="id" value="<?php echo $id?>" />
    <input type="submit" value="SUBMIT" /></p>
    </form>

    <?php endif; ?>

    </body>
    </html>

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The problem is with this line:
    PHP Code:
    if (isset($_POST['category']));
    /*The country's details have been updated.*/ 
    You've got a semicolon on the end, there, rather than a colon.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,376
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank You Very Much!!


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
  •