Jump to content

Recommended Posts

if(isset($_COOKIE['Username']) && $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 "<input type=\"text\" name=\"title\" size=\"20\" maxlength=\"20\" tabindex=\"2\" class=\"post\" value=\"{$i['Title']}\" /><br><textarea name=\"message\" rows=\"15\" cols=\"35\" wrap=\"virtual\" style=\"width:450px\" tabindex=\"3\" class=\"post\">{$i['Text']}</textarea><br><input name=\"submitnews\" type=\"submit\" value=\"Submit News\">";
			[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();
}

The proper flow of the form should be, Select news story to edit -> get news story from DB and put in a text field to edit -> submit

 

However after the news story is selected from the DB and put in the text field for editing, and the submit button is clicked, the UPDATE **** SET sql code isn't executed, the server directs the user back to the form to select the news story to edit. I'm stumped as to why this is happening, can anyone offer some insight?  ???

 

if(!isset($submit)) checks to see if the first form (dropdown to select news story) is set otherwise it displays the news post editing box.

$submit = $_POST['submit']; $_POST['submit'] is the name of the submit button on the select news post form.

 

if(!isset($submitnews)) checks to see if the news post editing form has been completed.

$submitnews = $_POST['submitnews']; $_POST['submitnews'] is the name of the submit button on the news editing post form.

 

 

Link to comment
https://forums.phpfreaks.com/topic/83256-layered-form-problem/
Share on other sites

Looks like you are trying to use $i as an associate array when it's numerical.  Try using mysql_fetch_assoc instead of array or use $i[0] (where 0 is the array index of the Poster field.

 

$i = mysql_fetch_array($sql);

if($i['Poster'] == $_COOKIE['Username']){

 

Link to comment
https://forums.phpfreaks.com/topic/83256-layered-form-problem/#findComment-423632
Share on other sites

Sorry, maybe I didn't explain it well enough..

 

http://71.111.91.20/test.php is the demo.

 

Notice how the story selection works, and when the edit form comes up it's still fine, however when you make the change to the post and go to submit the revision, it reverts back to the story selection.

 

Hope thats a bit clearer?  ???

Link to comment
https://forums.phpfreaks.com/topic/83256-layered-form-problem/#findComment-423717
Share on other sites

I guess the root of my problem is, a select box, selecting the post to edit, a text area to change the post. Once the text box is submitted, the update query isn't performed, and I'm taken back directly to the selection box, see http://71.111.91.20/test.php for example.

Link to comment
https://forums.phpfreaks.com/topic/83256-layered-form-problem/#findComment-424567
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.