Specifications

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) {
echo “There was a database error when executing <PRE>$sql</PRE>”;
echo 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: echo “Invalid picture format: $picture_type”;
}
}
header(“Location: $destination”);
?>
Building Practical PHP and MySQL Projects
P
ART V
610
LISTING 26.7 Continued
32 7842 ch26 3/6/01 3:36 PM Page 610