I'm trying to make a simple way to edit a news/blog system for my site, and have it so the editing is all from one page. So far, i've got it so that you can select which entry (of the last 16 entries) you wish to edit and when you hit submit, it will go to the form to edit the entry along with all the data from the database in the form fields of the entry you chose.
When you are done with editing, and hit submit, it doesn't update the database and the page just stays at the editing form.
Here is the thingy that controls what happens when you hit submit:
if(($_POST['Submit']) && ($edit == 0)) {
$edit = 1;
} else if (($_POST['Submit']) && ($edit == 1)) {
$title = addslashes($_POST['title']);
$nbcontent = addslashes($_POST['nbcontent']);
mysql_connect($mysql_server,$mysql_username,$mysql_password);
mysql_select_db($mysql_database);
mysql_query("UPDATE newsblog SET title='$title', nbcontent='$nbcontent', author='{$_POST['author']}', type='{$_POST['type']}') WHERE id='{$_POST['id']}'");
mysql_close();
$edit = 0;
header('Location: newsblog.php');
}
The first part works fine, but the second part doesn't work. The part which shows what part of the form should be shown at the time is below, and once again, the first bit works, the second bit shows and everything seems fine, but when you hit submit, nothing gets updated.
<?php
if ($edit == 0) {
?>
<h1>Edit News / Blog Entry!</h1>
<p>Select the news / blog entry below that you wish to edit from
the site database. You may only select from the last 16 entries
to the database, to make it simpler for updating recent
entries.</p>
<form action="" enctype="multipart/form-data" method="post" name=
"edit-newsblog" id="edit-newsblog">
<table>
<tr>
<td class="left">
<p>Select</p>
</td>
<td valign="top" class="right"><select name="id" size="1"><?php
mysql_connect($mysql_server,$mysql_username,$mysql_password);
mysql_select_db($mysql_database);
$result = mysql_query("SELECT * FROM newsblog ORDER BY id DESC LIMIT 16");
$qresult = mysql_fetch_array($result);
while ($qresult != false) {
echo "<option value=\"".$qresult['id']."\">".$qresult['title']."</option>";
$qresult = mysql_fetch_array($result);
}
mysql_close();
?></select></td>
</tr>
</table>
<table>
<tr>
<td valign="top"><input name="Submit" type="submit" id="submit"
value="Submit"> <input name="Clear" type="reset" id="clear"
value="Clear"></td>
</tr>
</table>
</form>
<?php
} else if ($edit == 1) {
?>
<h1>Edit News / Blog Entry!</h1>
<p>Fill out the following form completely to successfully edit
the news/blog entry that you had selected on the previous
page.</p>
<?php
mysql_connect($mysql_server,$mysql_username,$mysql_password);
mysql_select_db($mysql_database);
$result = mysql_query("SELECT * FROM newsblog WHERE id='{$_POST['id']}'");
$qresult = mysql_fetch_array($result);
$string = stripslashes($qresult['nbcontent']);
$title = stripslashes($qresult['title']);
?>
<form action="" enctype="multipart/form-data"
method="post" name="edit-newsblog" id="edit-newsblog">
<?php echo "<input name=\"id\" type=\"hidden\" id=\"id\" value=\"".$_POST['id']."\">";?>
<table>
<tr>
<td class="left">
<p>Title</p>
</td>
<td valign="top" class="right">
<?php echo "<input name=\"title\" type=\"text\" id=\"title\" class=\"text\" value=\"". $title ."\">";?></td>
</tr>
<tr>
<td class="left">
<p>Type</p>
</td>
<td valign="top" class="right"><select name="type" size="1">
<option value="Announcement">Announcement</option>
<option value="Site Update">Site Update</option>
<option value="Rant">Rant</option>
</select></td>
</tr>
</table>
<table style="width:400px;">
<tr>
<td valign="top">
<p style="margin:0px;font-weight:bold;">News/Blog Content</p>
</td>
</tr>
<tr>
<td valign="top">
<textarea name="nbcontent" id="nbcontent">
<?php echo $string;?>
</textarea></td>
</tr>
</table>
<?php
mysql_connect($mysql_server,$mysql_username,$mysql_password);
mysql_select_db($mysql_database);
$result = mysql_query("SELECT * FROM users WHERE username='{$_COOKIE['username']}'");
$qresult = mysql_fetch_array($result);
echo "<input name=\"author\" type=\"hidden\" id=\"author\" value=\"".$qresult['display']."\">";
?>
<table>
<tr>
<td valign="top"><input name="Submit" type="submit" id="submit"
value="Submit"> <input name="Clear" type="reset" id="clear"
value="Clear"></td>
</tr>
</table>
</form>
<?php
}
?>
I've got no idea what the problem is, as it looks to me that it should work. Any help would be appreciated.:queasy: