cybernet Posted May 10, 2011 Share Posted May 10, 2011 i have two pages form and submit page index.php <?php error_reporting(E_ALL); $bauturi = array('bauturi_alcoolice'=>'Bauturi alcoolice','sucuri'=>'Sucuri','bauturi_racoritoare'=>'Bauturi racoritoare'); echo '<form action="post.php" method="post">'; echo'<select name="bauturi">'; foreach($bauturi as $let=>$word){ echo'<option value="'.$let.'">'.$word.'</option>'; } echo'</select>'; echo '<INPUT type="submit" value="show me money"> </form>'; ?> post.php <?php error_reporting(E_ALL); $drop = $_REQUEST['bauturi']; echo $drop; ?> if i select Bauturi alcoolice on post.php page i get bauturi_alcoolice but i want to get Bauturi alcoolice as result i tried to use foreach like this <?php error_reporting(E_ALL); $drop = $_REQUEST['bauturi']; $bauturi = array('bauturi_alcoolice'=>'Bauturi alcoolice','sucuri'=>'Sucuri','bauturi_racoritoare'=>'Bauturi racoritoare'); foreach($bauturi as $drop=>$word){ echo $word; echo "<br/>"; unset($word); } ?> but i get all the values in the form i only want to show the selected value from the form in post.php page thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/236022-array-issues/ Share on other sites More sharing options...
AbraCadaver Posted May 10, 2011 Share Posted May 10, 2011 foreach($bauturi as $word){ echo'<option>'.$word.'</option>'; } Quote Link to comment https://forums.phpfreaks.com/topic/236022-array-issues/#findComment-1213377 Share on other sites More sharing options...
cybernet Posted May 10, 2011 Author Share Posted May 10, 2011 i don't think you understood me index.php is flawless ( i think ) if on index.php i select Bauturi alcoolice on post page i wanna get Bauturi alcoolice this code is good <?php error_reporting(E_ALL); $drop = $_REQUEST['bauturi']; echo $drop; ?> but as result i get bauturi_alcoolice instead of the value that is equal with it Quote Link to comment https://forums.phpfreaks.com/topic/236022-array-issues/#findComment-1213382 Share on other sites More sharing options...
AbraCadaver Posted May 10, 2011 Share Posted May 10, 2011 I understood exactly. Did you try what I posted? index.php is not flawless, you are sending the array key bauturi_alcoolice as the value instead of send the value Bauturi alcoolice as the value. I'm not even sure why you are setting a key name in your array. With the code I posted, this works just as well: $bauturi = array('Bauturi alcoolice','Sucuri','Bauturi racoritoare'); Also, there will be only one posted value, so no need for a loop in post.php. Try: echo $_POST['bauturi']; Quote Link to comment https://forums.phpfreaks.com/topic/236022-array-issues/#findComment-1213397 Share on other sites More sharing options...
cybernet Posted May 10, 2011 Author Share Posted May 10, 2011 thanks for being patient with me it worked Quote Link to comment https://forums.phpfreaks.com/topic/236022-array-issues/#findComment-1213432 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.