Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/236022-array-issues/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/236022-array-issues/#findComment-1213382
Share on other sites

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'];

 

 

Link to comment
https://forums.phpfreaks.com/topic/236022-array-issues/#findComment-1213397
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.