PAGE 1 LISTS CATEGORIES. it highlights the category with a link which takes it to page 2.
Code: Select all
<p>Category Name:<br />
<?php
error_reporting (E_ALL ^ E_NOTICE);
$dbcnx = @mysql_connect('localhost', 'root', 'onlyiknow');
if (!$dbcnx) {
exit('<p>Unable to connect to the database server at this time.</p>');
}
if (!@mysql_select_db('db')) {
exit('<p>Unable to locate the database at this time.</p>');
}
$result = mysql_query("SELECT * FROM currencies");
$num_rows = mysql_num_rows($result);
echo "There are $num_rows currency types\n";
$cats = @mysql_query('SELECT currencyid, categoryname FROM currencies');
if (!$cats) {
exit('<p>Error retrieving currency types from the database!<br />'.
'Error: ' . mysql_error(). '</p>');
}
while ($cat = mysql_fetch_array($cats)) {
$id = $cat['currencyid'];
$name = htmlspecialchars($cat['categoryname']);
echo "<li><a href='editcurrency.php?id=$id'>$name</a>";
}
?>
</ul><form>
<input type="hidden" value="<?php echo $id; ?>" />
</form>PAGE 2 displays the correct currency type in a textbox, but then gives me an error that id isnt defined.
Code: Select all
<?php
$dbcnx = @mysql_connect('localhost', 'root', 'onlyiknow');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
if (!@mysql_select_db('db')) {
exit('<p>Unable to locate the ' .
'database at this time.</p>');
}
if (isset($_POST['name'])):
// The details have been updated.
$name = $_POST['name'];
$getid = $_POST['id'];
$sql = "UPDATE author SET
CategoryName='$name',
WHERE categoryid='$id'";
if (@mysql_query($sql)) {
echo '<p>Details updated.</p>';
} else {
echo '<p>Error updating details: ' .
mysql_error() . '</p>';
}
?>
<p><a href="currencies.php">Return to currencies list</a></p>
<?php
else: // Allow the user to edit the currency
$id = $_GET['id'];
$category = @mysql_query(
"SELECT CategoryName FROM currencies WHERE CurrencyID='$id'");
if (!$category) {
exit('<p>Error fetching currency details: ' .
mysql_error() . '</p>');
}
$category = mysql_fetch_array($category);
$name = $category['CategoryName'];
// Convert special characters for safe use
// as HTML attributes.
$name = htmlspecialchars($name);
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Edit the Currency:</p>
<label>Name: <input name="Name" type="text" id="Name" value="<?php echo $name; ?>" /></label><br /><br />
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<input type="submit" value="SUBMIT" /></p>
</form>
<?php endif; ?>Thanks.