drummer101 Posted December 25, 2007 Share Posted December 25, 2007 if(isset($_COOKIE['Username']) && $_COOKIE['Auth'] == 2){ @$submit = $_POST['submit']; if(!isset($submit)){ echo "<form name=\"edit_news\" method=\"post\">"; echo "<select name=\"news_story\">"; echo "<option selected=\"selected\" value=\"\">Please select a news story</option>"; $sql= mysql_query("SELECT * FROM `****` ORDER BY ****.Number DESC"); //$number= mysql_query("SELECT ****.Number FROM `****`"); echo mysql_error(); if (mysql_num_rows($sql)>0){ //if there are records in the fields $numrows=mysql_num_rows($sql); //count them $x=0; while ($x<$numrows){ //loop through the records $result=mysql_fetch_array($sql); //place each record in the variable everytime we loop echo "<option value=\"{$result['Number']}\">{$result['Date']} - {$result['Title']}</option>\n"; //and place it in the select $x++; } } echo "</select><br>"; //close the select echo "<input type=\"submit\" value=\"Edit News Story\" name=\"submit\"></form>"; } else { $story_id = $_POST['news_story']; $sql = mysql_query("SELECT * FROM `****` WHERE ****.Number = '$story_id'"); $i = mysql_fetch_array($sql); if($i['Poster'] == $_COOKIE['Username']){ @$submitnews = $_POST['submitnews']; if(!isset($submitnews)){ echo "**Form code here**"; [b]} else { @$text = addslashes($_POST["message"]); @$title = addslashes($_POST['title']); $sql = mysql_query("UPDATE `****` SET `Text` = '$text', `Title` = '$title' WHERE `Number` = '$story_id'") or die ("MySQL error<br>mysql_error()"); echo "Update successful"; }[/b] } else { echo "<font color=\"#FF0000\"><b>You are not authorized to edit this post as it is someone elses. Please contact the webmaster if there is a problem.</b></font>"; } } } else { echo "<font color\"#FF0000\"><b>You are not authorized to access this page, please login to continue</b></font><br><br>"; login(); } If the username & auth level are correct, display the form IF $submit isn't set, query the DB for the stories posted, once selected display the story edit form. Here's where it breaks. Once the story has been edited, and the user goes to post the revision, when you click submit, it kicks back out to the story selection form without throwing any exceptions. @$submitnews = $_POST['submitnews']; is the story revision submit button's name Quote Link to comment https://forums.phpfreaks.com/topic/83151-data-editing-with-forms/ Share on other sites More sharing options...
crashmaster Posted December 25, 2007 Share Posted December 25, 2007 its not safe to use COOKIE['Auth'] Quote Link to comment https://forums.phpfreaks.com/topic/83151-data-editing-with-forms/#findComment-422925 Share on other sites More sharing options...
drummer101 Posted December 25, 2007 Author Share Posted December 25, 2007 its not safe to use COOKIE['Auth'] Okay well I'll switch it over to a DB field then... Edit: I just figured out whats going on, Once the first submit button is pressed that variable is set, however, once the second button is pressed, the first is destroyed, so the code displays the story selection again. Is there any way to get this to work on one page or should I just separate it out and have a handle page? Quote Link to comment https://forums.phpfreaks.com/topic/83151-data-editing-with-forms/#findComment-422929 Share on other sites More sharing options...
drummer101 Posted December 25, 2007 Author Share Posted December 25, 2007 bump for question ??? Quote Link to comment https://forums.phpfreaks.com/topic/83151-data-editing-with-forms/#findComment-423028 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.