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:
This is the code in the editcountry.php page. I can’t find any reason for the error:PHP Code:else: /*Allow the user to edit the country*/
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>





Bookmarks