<?PHP
mysql_select_db("general");
$result = mysql_query("SELECT user_admin FROM users WHERE user_name = '".$_SESSION['user_name']."' ");
$result = mysql_fetch_array($result);
$user_admin = $result['user_admin'];
if ($user_admin==0) {
echo "<div align=center><span class=text>You are not an administrator. If you think you are supposed to be, click Contact Webmaster.</span></td><td width=550> ";
} else {
// if post var doesnt exist display the users
if (isset($_POST['editnews']) && $_POST['editnews'] != "")
{
if (isset($_POST['newstopic'])) {
// ---------------------------THIS IS LAST STAGE, THIS IS WHERE THE NEWS IS SUBMITTED AND THE SUCCESS MESSAGE IS DISPLAYED
# setup SQL statement
$SQL = " UPDATE users SET";
$SQL = $SQL . " news_topic = '".$_POST['newstopic']."', ";
$SQL = $SQL . " news_body = '".$_POST['newsbody']."', ";
$SQL = $SQL . " news_by = '".$_POST['newsby']."', ";
# execute SQL statement
$result = mysql_query($SQL);
# check for errors
if (mysql_error()) {
echo("ERROR: " . mysql_error() . "\n$SQL\n");
}else{
echo (":: news has been edited ::<br><a href=adminpanel.php target=main>:: go to admin panel ::</a><a href=editnews.php target=main>:: back to edit news ::</a>\n");
}
// ---------------------------THIS IS THE POINT IN WHERE THEY EDIT THE NEWS
} else {
$sql = "SELECT * FROM news WHERE news_id = '".$WHAT VAR GOES HERE?."' ";
$result = mysql_query($sql);
if(mysql_num_rows($result)) {
while ($row = mysql_fetch_array($result)) {
$newstopic = $row["news_topic"];
$newsbody = $row["news_body"];
$newsby = $row["news_by"];
} // while
} // if
echo "
<form name='edit' method='post' action='editnews.php'>
TOPIC:<input type='text' name='newstopic' value='".$news_topic."' />
BODY:<input type='text' name='newsbody' value='".$news_body."' maxlength='255'/>
BY:<input type='text' name='newsby' value='".$news_by."' maxlength='30' />
Finalize:<input type='submit' name='submit' value='Edit News' />
</form>";
}
// ----------------------BELOW IS FIRST STAGE, SELECTING THE NEWS TO EDIT
}else{
// get news
$get_news = mysql_query("SELECT news_id,news_topic FROM news ORDER BY news_id DESC");
// display the news
print '<form action="'.$PHP_SELF.'" method="post">';
print '<select name="editnews">';
while ($urow = mysql_fetch_object($get_news))
{
print '<option value="'.$urow->news_id.'">'.$urow->news_topic.'</option>';
}
print '</select>';
print '<input type="submit" name="submit" value=":: edit news ::" /></form>';
}
}
?>
i have this script, and if you look at it closely, the order goes: 1. select a news input, 2. goes to a page where the info should be displayed to edit, 3. the edit query is run and the success message is displayed
the only thing is, once you select the news post you want to edit, you have to run a query to select taht row
what i cant figure out is here:
} else {
$sql = "SELECT * FROM news WHERE news_id = '".$WHAT VAR GOES HERE?."' ";
$result = mysql_query($sql);
anyone who actually understands what my dumb mind is saying here, id apreciate any help