PHP HTML, put input form variable to dict

Issue

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..

Solution

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

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

Answered By – Barmar

Answer Checked By – Dawn Plyler (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.