trouble passing correct POST variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
slash_gnr3k
Forum Commoner
Posts: 43
Joined: Tue Nov 28, 2006 6:41 pm

trouble passing correct POST variables

Post by slash_gnr3k »

i have the following code

Code: Select all

	<form action = "<?php echo "../autoplan.php?dish1='$dish1'"; ?>" method = "post" name = "editmenu">

	<?php 
		//connect to server and database
		include_once '../includes/connect.inc.php';

		echo "<h2>Edit Vegetarian Dish Suggestions</h2>";

		//add parameters passed from autoplan.php into an array. each array element holds a meal
		//that autoplan.php suggested			
		$suggesteddishes = array();
		$suggesteddishes[1] = $dish1;
		$suggesteddishes[2] = $dish2;
		$suggesteddishes[3] = $dish3;
		$suggesteddishes[4] = $dish4;
		$suggesteddishes[5] = $dish5;
		$suggesteddishes[6] = $dish6;
		$suggesteddishes[7] = $dish7;
		$vsuggesteddishes[1] = $dish8;
		$vsuggesteddishes[2] = $dish9;
		$vsuggesteddishes[3] = $dish10;
		$vsuggesteddishes[4] = $dish11;
		$vsuggesteddishes[5] = $dish12;
		$vsuggesteddishes[6] = $dish13;
		$vsuggesteddishes[7] = $dish14;
			
		$iterationno = 1;
			
		//create 7 drop down boxes
		while($iterationno < 8)
		{

			//select the names of all vegetarian dishes from the database
			$getalldishes = @mysql_query("SELECT name FROM dishes WHERE vegetarian = 'Yes'")or die(mysql_error());


			echo "<p><select name = \"newdish$iterationno\" size = 1>";

			//default option in list in iteration number in suggested dishes array which is the name in the dish name
			//variable passed from autoplan.php
			echo"<option selected value =\"{$suggesteddishes[$iterationno]}\">{$suggesteddishes[$iterationno]}</option>";			

			//loop to retrieve all records that satisfy query
			while ($row = mysql_fetch_array($getalldishes))
			{

				//gets each value from database and makes it an option in the list
				echo"<option value =\"{$row['name']}\">{$row['name']}</option>";

			}
			
			echo"</select></p>";


			$iterationno++;


		}

		$IT = 1;

			
		//create 7 drop down boxes
		while($IT < 8)
		{

			//select the names of all vegetarian dishes from the database
			$getallnonvegdishes = @mysql_query("SELECT name FROM dishes WHERE vegetarian = 'No'")or die(mysql_error());


			echo "<p><select name = \"newnonvegdish$IT\" size = 1>";

			//default option in list in iteration number in suggested dishes array which is the name in the dish name
			//variable passed from autoplan.php
			echo"<option selected value =\"{$vsuggesteddishes[$IT]}\">{$vsuggesteddishes[$IT]}</option>";			

			//loop to retrieve all records that satisfy query
			while ($row = mysql_fetch_array($getallnonvegdishes))
			{

				//gets each value from database and makes it an option in the list
				echo"<option value =\"{$row['name']}\">{$row['name']}</option>";

			}
			
			echo"</select></p>";

			$IT++;
		

		$dish1 = $_POST['newdish1'];

	?>
which takes in values from the page this is accessed from, creates 14 drop down boxes in total with the passed parameter as the default for each box. on the click of the button the page loads the correct page and passes the parameter which is the value of the field newdish1 (obviously there this will happen for each field but im tring to get it working for 1) however if the user changes the value, the same value is passed back that was passed in. why is the value not being updated? i hope this makes sense!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: trouble passing correct POST variables

Post by John Cartwright »

slash_gnr3k wrote:i hope this makes sense!
Nope, not really :wink:
slash_gnr3k
Forum Commoner
Posts: 43
Joined: Tue Nov 28, 2006 6:41 pm

Post by slash_gnr3k »

ok ill try to explain it better.

this page is accessed through a page called autoplan.php which passes this page - editplan.php 14 parameters. editplan.php creates 14 drop down boxes populated with records from the database. each respective box has its selected attribute as its respective parameter EG 1st drop down box has first parameter selected, 2nd box has 2nd parameter etc...

when clicking the button, the system opens autoplan.php and passes back the 14 parameters which should now have been updated depending on what the user selected in each drop down menu. my problem is, when passing back the parameters, they have not changed even if the user has selected something different, they stay the same as when they were initially passed from autoplan.php

hope this makes things a bit clearer!
Post Reply