drummer101 Posted December 26, 2007 Share Posted December 26, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/83256-layered-form-problem/ Share on other sites More sharing options...
drummer101 Posted December 26, 2007 Author Share Posted December 26, 2007 Bump, 18 views nobody has a sugestion? Quote Link to comment https://forums.phpfreaks.com/topic/83256-layered-form-problem/#findComment-423622 Share on other sites More sharing options...
revraz Posted December 26, 2007 Share Posted December 26, 2007 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']){ Quote Link to comment https://forums.phpfreaks.com/topic/83256-layered-form-problem/#findComment-423632 Share on other sites More sharing options...
drummer101 Posted December 26, 2007 Author Share Posted December 26, 2007 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? ??? Quote Link to comment https://forums.phpfreaks.com/topic/83256-layered-form-problem/#findComment-423717 Share on other sites More sharing options...
teng84 Posted December 26, 2007 Share Posted December 26, 2007 sorry but i cant find the codes that determine your form action when you don't put any form action it will return to it self which is your test.php and can you tell us where do you want the page to go after submission? Quote Link to comment https://forums.phpfreaks.com/topic/83256-layered-form-problem/#findComment-423722 Share on other sites More sharing options...
drummer101 Posted December 26, 2007 Author Share Posted December 26, 2007 Form action should be self. If I have to separate it and have a handle page thats fine, but if at all possible I'd prefer to keep it on the same page. Quote Link to comment https://forums.phpfreaks.com/topic/83256-layered-form-problem/#findComment-423752 Share on other sites More sharing options...
drummer101 Posted December 27, 2007 Author Share Posted December 27, 2007 bump :-\ Quote Link to comment https://forums.phpfreaks.com/topic/83256-layered-form-problem/#findComment-423913 Share on other sites More sharing options...
drummer101 Posted December 27, 2007 Author Share Posted December 27, 2007 Morning bump, I'm still stumped ??? Quote Link to comment https://forums.phpfreaks.com/topic/83256-layered-form-problem/#findComment-424201 Share on other sites More sharing options...
drummer101 Posted December 28, 2007 Author Share Posted December 28, 2007 bedtime bump :-X Is it even possible to nest two forms within IF statements on the same page? Has anyone had success doing it? Quote Link to comment https://forums.phpfreaks.com/topic/83256-layered-form-problem/#findComment-424492 Share on other sites More sharing options...
teng84 Posted December 28, 2007 Share Posted December 28, 2007 you can have more forms in one page but the only data that will be submitted is the data (within that form ) Quote Link to comment https://forums.phpfreaks.com/topic/83256-layered-form-problem/#findComment-424494 Share on other sites More sharing options...
drummer101 Posted December 28, 2007 Author Share Posted December 28, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/83256-layered-form-problem/#findComment-424567 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.