Can someone please explain to me why this code doesn't work correctly?
I know it's a bit messy, but I'm a newb!
The code displays data from a record in a form and allow the user to change it. It should, once the submit button is clicked, update the record with the new data. It runs through fine and never gives any errors but the record is not updated.
I think the problem could be than it's actually updating the record with the old data, but I'm not sure.
Can anyone spot my problem?
<?php
session_start();
if (!$_SESSION["valid_user"])
{
// User not logged in, redirect to login page
Header("Location: login.php");
}
include ("dbConfig.php");
$result = mysql_query("SELECT * FROM posts WHERE id='$id'");
$myrow = mysql_fetch_array($result);
$user = $myrow["user_id"];
$title = $myrow["title"];
$text = $myrow["text"];
?>
<META name="description" content="ITComedy.com your complete tech humor web site!">
<META name="keywords" content=", itcomedy, it comedy, tech humor,tech support, tech
support humor, computer humor, tech humor, helpdesk,humor,
tech support sories, computer tech humor, computer stories, computer, support humor,
help desk, humor">
<title>ITCOMEDY.COM :: Tech Support Comedy</title>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse"
width="621" id="AutoNumber1">
<tr>
<td width="621" colspan="5"><?php
virtual('title.htm');
?></td>
</tr>
<tr>
<td width="467" colspan="3" rowspan="5" valign="top">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse"
width="100%" id="AutoNumber3" height="7">
<tr>
<td width="100%" colspan="3" height="12"><font size="1"> </font></td>
</tr>
<tr>
<td width="100%" colspan="3" height="19">
<img border="0" src="images/postmessage.jpg"></td>
</tr>
<tr>
<td width="33%" height="1"></td>
<td width="33%" height="1"></td>
<td width="34%" height="1"></td>
</tr>
<tr>
<td width="100%" height="19" colspan="3">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse:
collapse" width="100%" id="AutoNumber4" height="1">
<tr>
<td width="1%" height="1"><font size="2"> </font></td>
<td width="33%" height="1"><font face="Verdana" size="2"> </font></td>
<td width="1%" height="1"><font size="2"> </font></td>
<td width="68%" height="1"><font face="Verdana" size="2"> </font></td>
</tr>
<tr>
<td width="103%" height="1" colspan="4"><font face=verdana size=2>
<?php
if ($submit) {
include ("dbConfig.php");
$query="UPDATE posts SET title_update='$title', text_update='$text' WHERE id='$id'";
mysql_query($query);
echo "Thank you! Your changes have been saved.\n";
} else{
?>
<form method="post" action="<?php echo $PHP_SELF?>">
Subject: <input type="Text" name="title_update" value="<?php echo
"$title"; ?>"><br>
<br>Message:<br> <textarea rows="10" name="text_update" cols="40"><?php echo "$text";
?></textarea><br><br>
<input type="Submit" name="submit" value="Save Changes">
</form>
<?php
} // end if
?>
</td>
</tr>
<tr>
<td width="15%" height="1"><font size="1"> </font></td>
<td width="18%" height="1"><font size="1"> </font></td>
<td width="14%" height="1"><font size="1"> </font></td>
<td width="53%" height="1"><font size="1"> </font></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td width="8"> </td>
<td width="146" rowspan="5" valign="top">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse"
width="100%" id="AutoNumber2">
<tr>
<td width="100%"><font size="1"> </font></td>
</tr>
<tr>
<td width="100%"><img border="0" src="images/latestposts.jpg"></td>
</tr>
<tr>
<td width="100%"><font size="2"> </font></td>
</tr>
<tr>
<td width="100%"><?php
virtual('rightbar.php');
?></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="8"> </td>
</tr>
<tr>
<td width="8"> </td>
</tr>
<tr>
<td width="8"> </td>
</tr>
<tr>
<td width="8"> </td>
</tr>
<tr>
<td width="621" colspan="5">
<img border="0" src="images/bottombar.jpg"></td>
</tr>
<tr>
<td width="125"> </td>
<td width="124"> </td>
<td width="218"> </td>
<td width="8"> </td>
<td width="146"> </td>
</tr>
<tr>
<td width="621" colspan="5"><font face="Verdana">
<p align="center"><font size="1">ITComedy.com (c) 2003
<a href="mailto:Dave@itcomedy.com">Dave</a> all rights reserved. <br>
Any and all trademarks acknowledged.</font></font></td>
</tr>
</table>
</center>
</div>