Jump to content

Data editing with forms


drummer101

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.