Edit Form
Posted: Wed Feb 09, 2005 5:04 pm
Hey,
Trying to create an update news form .. its parsing thru saying it was successfull .. but the record hasnt been updated at all
editnews.php:
editnewsparse.php:
Any ideas why its not updating?
Thanks
Trying to create an update news form .. its parsing thru saying it was successfull .. but the record hasnt been updated at all
editnews.php:
Code: Select all
<?php
include 'db.php';
define('MAX_YEARS', 5);
$sql = mysql_query("SELECT * FROM teachers_news WHERE id='{$_GETї'id']}'");
while($row = mysql_fetch_array($sql)){
$id = $rowї'id'];
$news = $rowї'$news'];
$date = $rowї'date'];
?>
<form action="../index.php?pages=editnewsparse" method="post">
<input type="hidden" name="id" value="<?php echo $rowї'id']; ?>">
<table width="400" border="0" align="center" cellpadding="4" cellspacing="0">
<tr>
<td width="100" align="right"><font class="txt">Date:</font></td>
<td width="278" align="left">
<select name="day" id="day" class="input-box">
<?php
$currentDay = date('j');
for ($day = 1; $day <= 31; $day++) {
echo "<option";
if ($currentDay == $day) echo " SELECTED";
echo ">$day</option>\n";
}
?>
</select> <select name="month" id="month" class="input-box">
<?php
$currentMonth = date('n');
for ($month = 1; $month <= 12; $month++) {
echo "<option";
if ($currentMonth == $month) echo " SELECTED";
echo ">$month</option>\n";
}
?>
</select>
<select name="year" id="year" class="input-box">
<?php
$currentYear = date("Y");
for ($year = $currentYear; $year <= ($currentYear+MAX_YEARS-1); $year++) {
echo "<option";
if ($currentYear == $year) echo " SELECTED";
echo ">$year</option>\n";
}
?>
</select>
<font class="txt">dd-mm-yyyy</font></td>
</tr>
<tr>
<td align="right"><font class="txt">News:</font></td>
<td align="left"> <textarea name="news" cols="30" rows="5" id="description" class="input-box"><?php echo $rowї'news']; ?></textarea>
</td>
</tr>
<tr align="center">
<td colspan="2"> <input type="submit" name="Submit" value="Submit" class="submit-button">
</td>
</tr>
</table>
</form>
<?php
}
?>Code: Select all
<?php
include 'db.php';
define('MAX_YEARS', 5);
// Define post fields into simple variables
$id = (int)$_GETї'id'];
$news = (int)$_GETї'news'];
$year = (int)$_GETї'year'];
$month = (int)$_GETї'month'];
$day = (int)$_GETї'day'];
$currentYear = date('Y');
if ($year >= $currentYear && $year < $currentYear + MAX_YEARS && checkdate($month, $day, $year)) {
$Y = sprintf('%04s', $year);
$m = sprintf('%02s', $month);
$d = sprintf('%02s', $day);
$date = "$Y-$m-$d";
}
// Enter info into the Database.
$sql = "UPDATE teachers_news SET date = '$date', news = '$news' WHERE id = '$id'";
if(!$sql){
echo ("<center><font class="txt"There has been an error inserting the data. Please contact the webmaster.</font></center>");
} else {
echo ("<center><font class="txt">Sucessfully Updated</font></center><br><br>");
echo ("<center><font class="txt"><a href="../index.php?pages=teachers_news">BACK</a></font></center><br>");
}
?>Thanks