Home > Blockchain >  PHP HTML, put input form variable to dict
PHP HTML, put input form variable to dict

Time:06-02

This is input html form where in the first city , i write one of dict keys from $cities

 <form action="./select.php" method="POST">

    <p>
        <label for="1">First city:</label>
        <input type="text" name="first_city" id="1">
    </p>

enter image description here

Taking first value from the form data(input)

$first_city = $_REQUEST['first_city'];

$cities=array(
    "Полтава" => "важливий історичний центр, великий транспортний вузол України",
    "Маріуполь" => "значний порт і промисловий центр України",
    "Дніпро" => "місто в Україні на обох берегах річки Дніпро");

if(array_key_exists($first_city , $cities)) {
    echo "Done";
}

The result must be "Done". I write one from dict keys of $cities into input form on website and nothing print.Help plzzz.Maybe i miss smth..

CodePudding user response:

The user is entering spaces around the city name. Remove them with trim().

$first_city = trim($_REQUEST['first_city']);
  • Related