Hi guys,
this is kinda a huge post but I am stumped! I am currently building a backed control panel in php that consists of a login page and a control page. The user will login and then be able to edit the information on the site through the control panel such as news posts etc.
I am trying to keep the control panel to one PHP page. This has been working fine up until now. The section the user is working on is selected by a drop down menu form at the top of the page that is populated with news, contacts, links, etc. Once a section is selected the from is reloaded and an array of entires form the db is loaded along with a text area to add/edit them
I have it to the point where if a user selects the News section. They can add a News item or delete a news item. The problem i’ve run into to is the edit portion.
Each entry for the section is displayed with an Edit and Delete link. Clicking on the Delete link passes a variable through the URL which is used to run a MYSQL query to delete the news item with the matching id. That works fine.
Clicking on the Edit link passes Two variables through the URL one contains the text from the news item and is used to refill the text area. The other is the News items ID number. This is where the problem comes in. Once the textarea is filled in with the News item text it has to be Submitted. The form gets submitted and saves the New news text but the former ID is lost so a new item is created.
If any one has any ideas on how to preserve that variable or a work around it would be much appreciated.
thanks in advance
here is the code:
// IF NEWS IS SELECTED FROM THE Drop Down Menu AND SUBMITTED
if($_POST['edits_dd'] == "news_dd" || isset($news_txt) || isset($news_del) || isset($news_filler)){
?>
<!-- HTML for building the news editing form -->
<h3>Add a news item </h3>
<form action="edits.php" method="post">
<textarea name="news_txt"><?php echo $news_filler; ?></textarea>
<input type="hidden" name="save_holder" value="<?php $news_save; ?>"/>
<br />
<input type="submit" value="Submit" />
</form>
<br />
<?php
echo("save_holder value is... " . " " . $save_holder . "<br /><br /><br />");
echo("news_save value is... " . " " . $news_save ."<br /><br /><br />");
/// this section updates the database with new info
// if it is a fresh News post just add it too the db
if(isset($news_txt) and !isset($save_holder)){
$result = mysql_query("INSERT INTO NEWS ( DATE, TEXT, USER)
VALUES (NOW(), '$news_txt','$client')",$connect);
echo($news_save);
}
//if it is a edited post only add it to the post with the same id as the //one we're editing ($news_save)
if(isset($news_txt) and isset($save_holder)){
$result = mysql_query("UPDATE NEWS
SET TEXT='$news_txt'
WHERE ID='$save_holder')",$connect);
echo($news_save);
}
/// this is the deletion string. deletes the news entry with an id of $news_del
if(isset($news_del)){
$result = mysql_query("DELETE FROM NEWS WHERE id='$news_del' ",$connect);
}
/// this is the loop that aranges the news items in an array
$result = mysql_query("SELECT * FROM NEWS ORDER BY ID DESC",$connect);
//lets make a loop and get all news from the database
while($myrow = mysql_fetch_assoc($result))
{//begin of loop
//now print the results:
echo "
<div id='newsclips'>";
echo "
<div id='item'>{$myrow['DATE']}<br />".
"
{$myrow['TEXT']}<br /><br />".
"
- ".
"
{$myrow['USER']}<br />";
// Now print the options to (Read,Edit & Delete the news)
echo "<br>
|| <a href=\"edits.php?news_filler=$myrow[TEXT]&news_save=$myrow[ID]\">Edit</a>
|| <a href=\"edits.php?news_del=$myrow[ID]\">Delete</a><br><hr></div>";
}//end of loop
echo "</div>";
} //closes the news section
?>
</body>
</html>