Forum Moderators: coopster
I'm having trouble updating a record in mysql. I've tried a ton of variations and I can't seem to find my problem (I'm pretty bad with PHP lol)
Anyway, here's the code I'm using. If anyone can spot the problem, it'd be much appreciated.
<?php
// grab news id from url
$n = $_REQUEST['n'];
// grab form variables
$news_title = $_POST['news_title'];
$news_article = $_POST['news_article'];
$dbtable = 'news';
if($_REQUEST['submitted']==1) { // if information was posted, insert the data into the db
$result = mysql_query("UPDATE $dbtable SET news_title='$news_title', news_article='$news_article' WHERE news_id='$n'") or die(mysql_error());
// uncomment below for troubleshooting
//printf("Records updated: %d\n", mysql_affected_rows());
echo "<p>News entry saved. Click <a href=\"test.php\">here</a> to see the results.</p>";
} else { // if no information was posted, show the FCKeditor
$result = mysql_query("SELECT * FROM $dbtable WHERE news_id = '$n'") or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{
$news_id = $row["news_id"];
$news_title = $row["news_title"];
$news_article = $row["news_article"];
$news_date = $row["news_date"];
$news_expire = $row["news_expire"];
echo "<h1>Update News Article</h1>
<p>Please use the control below to edit existing articles in the database. It works like any word processor (like Microsoft Word or Works) so it should be pretty straightforward!</p>
<hr />
<form action=\"".$PHP_SELF."\" method=\"post\">
<p>News Title: <input type=\"text\" name=\"news_title\" value=\"".$news_title."\"></p>";
// initialise FCKeditor
$oFCKeditor = new FCKeditor('news_article') ;
$oFCKeditor->BasePath = 'fckeditor/' ;
$oFCKeditor->ToolbarSet = 'Basic';
$oFCKeditor->Value = $news_article ;
$oFCKeditor->Create() ;
echo "<input type=\"submit\" value=\"submit\">
<input type=\"hidden\" name=\"submitted\" value=\"1\">
</form>";
} // end of while
}
?>
<form action=\"".$PHP_SELF."\" method=\"post\">
<p>News Title: <input type=\"text\" name=\"news_title\" value=\"".$news_title."\"></p>"; snip
echo "<input type=\"submit\" value=\"submit\">
<input type=\"hidden\" name=\"submitted\" value=\"1\">
</form>"; The news ID isn't present so when the form is submitted that data isn't passed to the script, maybe try adding something like:
<input type=\"hidden\" name=\"n\" value=\"$news_id\">