1 Replies - 231 Views - Last Post: 04 March 2019 - 11:08 AM Rate Topic: -----

#1 norwegianlaks   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-March 19

Problem with printing out value with php post from drop down array

Posted 04 March 2019 - 10:47 AM

Hello guys, I am new to this forum. I cant manage to get my php code to work, after I select chosen currency, I want it
to show the last updated currency, which is K3. So when I pick BTC BItcoin, I want it to show: The last updated currency for BTC Bitcoin is 17. I would appreciate your help big time.

<?php
$v2 = array(
    "BTC" => array(
        "navn" => "Bitcoin",
        "k1" => "1",
        "k2" => "11",
        "k3" => "17"
    ),
    "ETH" => array(
        "navn" => "Ethereum",
        "k1" => "2",
        "k2" => "12",
        "k3" => "27"
    ),
    "LTC" => array(
        "navn" => "Litecoin",
        "k1" => "3",
        "k2" => "13",
        "k3" => "37"
    ),
    "XMR" => array(
        "navn" => "Monero",
        "k1" => "4",
        "k2" => "14",
        "k3" => "47"
    ),
    "XRP" => array(
        "navn" => "Ripple",
        "k1" => "5",
        "k2" => "15",
        "k3" => "57"
    )
);
echo "<form action = 'visvaluta1.php' method='post'><select name=''style='width: 200;'> >";
foreach($v2 as $key => $value) {
    echo "<option value=".$key.">".$key." ".$value['navn']."</option>";
}
echo "<input type='Submit'></select></form>";
?>

<!DOCTYPE HTML>
<html>  
<body>

Choose currency:
 Last updated currency for <?php echo $_POST["key"];?><br> is: <?php echo $_POST["value"]; ?>

</body>
</html>
 


Is This A Good Question/Topic? 0
  • +

Replies To: Problem with printing out value with php post from drop down array

#2 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2282
  • View blog
  • Posts: 6,971
  • Joined: 15-January 14

Re: Problem with printing out value with php post from drop down array

Posted 04 March 2019 - 11:08 AM

You're printing that form before the doctype, you should fix that. All of those elements go in the body.

If you want to submit the form and print the result, the first thing you need to do is give your select element a name or else nothing will be in $_POST. You can get the value of the select element in $_POST and use that to look up the item in $v2, e.g. $v2[$_POST['select']]['k3']
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1