I am completely stuck on this one.
I have a PHP script that gets data from a MySQL database and populates a form for editing. when the form is submitted all the fields are correctly updated except one that no matter what stays to the value given when the entry was created.
The problematic field is "date_archive". Any insight welcome.
Here's the edit script:
<?
include("CONNECTION SCRIPT");
include("template_topnl.inc");
$connection = mysql_connect($host,$user,$password)
or die ( mysql_error() );
$db = mysql_select_db($database,$connection)
or die ( mysql_error() );
$sql = "SELECT * FROM mag_toc WHERE id = '$id'";
if(!$result = mysql_query($sql))
{
print "DATABASE ERROR SELECTING LIST FROM mag_toc";
}
else
{
$row = mysql_fetch_array($result);
$toc_id = $row['id'];
$toc_title = $row['title'];
$toc_date_archive = $row['date_archive'];
$toc_page = $row['page'];
$toc_description = $row['description'];
$toc_body = $row['body'];
$toc_category = $row['category'];
$toc_id_ext = $row['id_ext'];
} // end else 1
?>
<form method="post" action="weeklynews_edited.php" onsubmit="return validateForm()" name="createForm">
<input type=hidden name="id" value="<? echo $toc_id ?>">
<input type=hidden name="category" value="<? echo $toc_category ?>">
<p class="header-blue" style="margin-top:0px; margin-bottom:10px">
Edit a weekly news entry:<br />
<span class="tburgundy">* required fields</span>
</p>
<b>Category*:</b><br />
<input name="category" type="radio" value="30"> News
<input name="category" type="radio" value="33"> News Analysis
<input name="category" type="radio" value="34"> My Business
<input name="category" type="radio" value="35"> Product News
<table border="0" cellspacing="2" cellpadding="4">
<tr>
<td rowspan="2" valign="top" bgcolor="#99CCFF">
<b>Title*:</b><br />
<input type="Text" size="50" name="title" value="<? echo $toc_title ?>"><br />
<b>Summary*:</b><br />
<textarea name="description" rows="5" cols="48">
<? echo $toc_description ?>
</textarea>
<br /><br />
<b>Body*:</b><br />
<textarea name="body" rows="20" cols="48">
<? echo $toc_body ?>
</textarea>
</td>
<td valign="top" bgcolor="#eeeeee">
<b>Publish date*</b><br />
(Format YYYY-MM-DD):<br />
<input type="Text" size="10" name="date_archive" value="<? echo $toc_date_archive ?>" maxlength="10">
<br />
<b>Rank:</b><br />
0 will be at the top, then 1, 2, etc.<br />
<input type="Text" size="10" name="page" value="<? echo $toc_page ?>" maxlength="10">
<br />
<b>Product Alert id:</b><br />
<input type="Text" size="10" name="id_ext" value="<? echo $toc_id_ext ?>" maxlength="10">
<?
if ($toc_id_ext)
{
echo "<a href=\"http://www.productalert.com.au\" target=\"pa\">link test</a>";
}
?>
</td>
</tr>
<tr>
<td valign="bottom" bgcolor="#CCCCCC">
<input type="Submit" name="submit" value="Edit"> <a href="weeklynews_delete.php?id=<? echo $toc_id ?>&title=<? echo $toc_title ?>">(DELETE)</a>
</td>
</tr>
</table>
</form>
And here's the updating script:
<?
include("CONNECTION SCRIPT");
include("template_topnl.inc");
$db = mysql_connect($host,$user,$password)
or die ( mysql_error() );
mysql_select_db($database,$db)
or die ( mysql_error() );
// escaping the quotes for insertion into DB
$st_title = addslashes($title);
$st_description = addslashes($description);
$st_body = addslashes($body);
// converting double line breaks
$st_body = str_replace("\n\n","</p><p>",$body);
// converting single line breaks
$st_body = str_replace("\n","<br />",$body);
// edit entry
$sql = "UPDATE mag_toc SET title='$st_title',description='$st_description',body='$st_body',category='$category',date_archive='$date_archive',page='$page',id_ext='$id_ext' WHERE id=$id";
// run SQL against the DB
$result = mysql_query($sql);
echo "<p class=\"header-blue\" style=\"margin-top:0px; margin-bottom:20px\">Record edited!</p>".$sql."<br />".$date_archive;
include("template_bottom.inc");
?>