How To Insert Html Select Value As Text In Mysql Via Php
Solution 1:
Are 775>Tbilisi, 776>Kutaisi static data in html? Simply you can create an array like
$regions = array('775'=>'Tbilisi','776'=>'Kutaisi');
and before processing form substitute values:
$region = $regions[$_POST['region']];
Solution 2:
Set up a switch statement with all the values listed and their corresponding names. The major advantage of this is that you have all possible "safe" values already listed, therefore if a user tries to use SQL injection, they won't be able to attack you because it will revert to your default case. However the disadvantage is that if there are lot of fields, you will have to list them all. I'm pretty sure there might be a way to hack the system, to get "innerHTML" property with the POST
request, but I'm not sure.
$region = $_POST["region"];
switch($region){
case"775":
$insert = "Tbilisi"break;
...//more cases
default:
//if no case matches, do something here
break;
}
Solution 3:
I don't know if you still need this info, but: 1. first of all, why don't you use the select option like this?
<optionvalue="Tbilisi">Tbilisi</option><optionvalue="Kutaisi">Kutaisi</option>
Then the Php will take the name directly.
- If for any reason, the option above is not possible, I would also suggest jQuery
use this (to post your value -as region name - to you php script):
$var = $("#regioni option:selected" ).text();
$.post( "your-php-script.php", { region:$var } );
this code above should be included in an event handler (onclick, onselect...) depending what you need. read more about jquery, you need it.
Post a Comment for "How To Insert Html Select Value As Text In Mysql Via Php"