Hi.
For the longest time now, I have been trying to create a CMS using PHP and MySQL. I can add to a database, and can delete from it, but when I try to do the Update command, nothing happens.
I can get the text from the DB to appear in text boxes, but when I change the text and resubmit it to the database, nothing happens. Please let me know what I'm doing wrong. Here is what the code looks like:
<?php
$dbcnx = @mysql_connect('localhost', 'login', 'password');
mysql_select_db('blog');
if (isset($_POST['submit'])):
// The details have
// been updated.
$Date = $_POST['Date'];
$Title = $_POST['Title'];
$ID = $_POST['ID'];
$Story = $_POST['Story'];
$sql = "UPDATE items SET
Date='$Date',
Title='$Title'
WHERE ID='$ID'";
if (@mysql_query($sql)) {
echo('<p>details updated.</p>');
} else {
echo('<p>Error updating details: ' .
mysql_error() . '</p>');
}
?>
<p><a href="list.php">Return to list</a></p>
<?php
else: // Allow the user to edit the author
// with ID=$id
$author=@mysql_query("SELECT Date, Title, Story
FROM items
WHERE ID='$ID'");
if (!$author) {
die('<p>Error fetching author details: ' .
mysql_error() . '</p>');
}
$author = mysql_fetch_array($author);
$Date = $author['Date'];
$Title = $author['Title'];
$Story = $author['Story'];
// Convert special characters for safe use
// as HTML attributes.
$Date = htmlspecialchars($Date);
$Title = htmlspecialchars($Title);
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p>Edit the author:<br />
ID: <input type="text" name="ID" value="<?=$ID?>" /><br />
Date: <input type="text" name="Date" value="<?=$Date?>" size="20" maxlength="255" /><br />
Title: <input type="text" name="Title" value="<?=$Title?>" size="20" maxlength="255" /><br />
Story:
<textarea name="Story" cols="60" rows="30" tabindex="textarea"><?=$Story?>
</textarea>
<br />
<input type="hidden" name="ID" value="<?=$ID?>" />
<input type="submit" name="submit" value="SUBMIT" /></p>
</form>
<?php endif; ?>
Please let me know where I'm messing up. Thanks.