How to fill a dropdownlist with PHP? [closed]

0

I was creating a dropdownlist field with the countries of the world, but there was something that bothered me since I was doing it through HTML and any user can modify the HTML code through the browser's development tool.

My question is how do I do it with PHP? I mean from a BD or from a php file. I have seen that they do it using an array with the countries, but it is not complete since they do not show the procedure to fill the dropdownlist .

    
asked by luis 11.12.2016 в 20:38
source

1 answer

0

Through ajax you can fill your list of countries. Example with JQuery: Customer side (web browser)

<script>
function getPaises(val) {
    $.ajax({
        type: "POST",
        url: "get_state.php",
        data:'pais_id=' + val,
        success: function(data){
            $("#listado_paises").html(data);
        }
    });
}
</script>

Side of the server you create a file called get_state.php that you get the list of your countries.

There you solve with the list, but you do not save that the user modifies the value that he sends you. The only solution is to create a valid data verification function, before saving in the database. Regardless of when you create the list of countries in a dynamic or static way, you should always do a verification. You can do it from the client (web browser) and on the server. What if or if you have to do, is on the side of the server that is the most important.

    
answered by 11.12.2016 / 22:03
source