Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PHP HTML, put input form variable to dict

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$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']);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading