I'm using "PHP and MySQL Web Development" published by SAMS and there seems to be a typo, or two or a hundred, in the book. I need to use the Web Content Management script. I get an error when I try to submit a story. Can somebody please tell me what is wrong with this script:
<?php
// story_action.php
// add / modify story record
include "include_fns.php";
$conn = db_connect();
$time = time();
if ( ($html) && (dirname($html_type) == "text") ) {
$fp = fopen($html, "r");
$story_text = addslashes(fread($fp, filesize($html)));
fclose($fp);
}
if ($story) { // It's an update
$sql = "update stories
set headline = '$headline',
story_text = '$story_text',
page = '$page',
modified = $time
where id = $story";
}
else { // It's a new story
$sql = "insert into stories
(headline, story_text, page, writer, created, modified)
values
('$headline', '$story_text', '$page', '$auth_user', $time, $time)";
}
$result = mysql_query($sql, $conn);
if (!$result) {
print "There was a database error when executing <PRE>$sql</PRE>";
print mysql_error();
exit;
}
if ( ($picture) && ($picture != "none") ) {
if (!$story)
$story = mysql_insert_id();
$type = basename($picture_type);
switch ($type) {
case "jpeg":
case "pjpeg": $filename = "pictures/$story.jpg";
copy ($picture, $filename);
$sql = "update stories
set picture = '$filename'
where id = $story";
$result = mysql_query($sql, $conn);
break;
default: print "Invalid picture format: $picture_type";
}
}
header("Location: $destination");
?>