WOW, this board rocks! Thanks for everybody's help.
Okay, per your suggestions, I commented out my code a bit more, hopefully it's a bit easier to digest. I think I did it correctly, but I could be wrong.
I also took phil_j_poore suggestion and revised my UPDATE statement, however, now it doesn't work at all. This is the error I receive if I change the image:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'image='../images/photos/HM_RandomTopCD2.gif' WHERE newsid='19''
And the error I receive if I don't change the image:
Invalid file type.
Here's the revised code per your guys suggestions.
Thanks again for all your help.
<?php
include 'DL_Config.php';
if ($submit)
{
// Grab form data...
$title = mysql_real_escape_string($_POST['title']);
$text1 = mysql_real_escape_string($_POST['text1']);
$text2 = mysql_real_escape_string($_POST['text2']);
if (!$title)
{
@unlink($_FILES['imagefile']['tmp_name']);
echo 'Error: News title is a required field. Please fill it.';
die;
}
// ****************** CHECK IMAGE FILE SIZE AND TYPE SECTION ************
// Check file size...
if ($_FILES['imagefile']['size'] <= 75000)
{
// Create path...
$path = '../images/photos/' . $_FILES['imagefile']['name'];
// Check file type...
switch ($_FILES['imagefile']['type'])
{
case 'image/jpg':
case 'image/jpeg':
case 'image/gif':
// Relocate file...
if (!@move_uploaded_file($_FILES['imagefile']['tmp_name'], $path))
{
@unlink($_FILES['imagefile']['tmp_name']);
die('Unable to relocate file.');
}
break;
default:
@unlink($_FILES['imagefile']['tmp_name']);
die('Invalid file type.');
}
// ****************** UPDATE SECTION ************
// UPDATE News table...
if (isset($path))
{
$extra = "image='$path'";
} else {
$extra = "";
}
$sql = "UPDATE news SET title='$title', text1='$text1', text2='$text2' ".$extra." WHERE newsid='$newsid' ";
$res = mysql_query($sql) or die(mysql_error());
// $sql = "UPDATE news SET title='$title', text1='$text1', text2='$text2', image='$path' WHERE newsid='$newsid' ";
@unlink($_FILES['imagefile']['tmp_name']);
if (mysql_affected_rows() > 0)
{
// Success!
echo '<meta http-equiv="Refresh" content="3;url=DL_Index.php">';
echo "<b>UPDATED!<br>You\'ll be redirected to the Admin Area in a couple seconds...Hold tight!";
}
else
{
// Failure!
echo 'Unable to create record.';
}
}
else
{
@unlink($_FILES['imagefile']['tmp_name']);
die('This file is too large.');
}
}
// ****************** END UPDATE ************
// ****************** SELECT SECTION ************
elseif($newsid)
{
$sql = "SELECT * FROM news WHERE newsid='$newsid'";
$res = mysql_query($sql) or die(mysql_error());
while($myrow = mysql_fetch_assoc($res))
{
$title = $myrow["title"];
$text1 = $myrow["text1"];
$text2 = $myrow["text2"];
$image = $myrow["image"];
// ****************** END SELECT ************
?>
<html>
<Body>
<p class="ParaTitle">Add News Article</p>
<!-- Edit Record Form -->
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<input type="hidden" name="newsid" value="<? echo $myrow['newsid']?>">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<td>Title:</td>
<td><input name="title" size="40" maxlength="255" value="<? echo $title; ?>"></td>
</tr>
<tr valign="top">
<td>Image:</td>
<td><input type="file" name="imagefile" value="<? echo $image; ?>"></td>
</tr>
<tr valign="top">
<td>First Paragraph:</td>
<td><textarea name="text1" rows="7" cols="50"><? echo $text1; ?></textarea></td>
</tr>
<tr valign="top">
<td>The rest of the article:</td>
<td><textarea name="text2" rows="10" cols="50"><? echo $text2; ?></textarea><br>
<input type="submit" name="submit" value="Update News Article"></td>
</tr>
</table>
</form>
<!-- End Edit Record Form -->
</Body>
</html>
<?
}//end of while loop
}//end else
?>