Manuelo Zumbadze Manuelo Zumbadze - 6 months ago 14
PHP Question

How to insert HTML select value as text in MySQL via PHP

I have this select field:
`

<select class="large-fld" id="regioni" name="region" value="" >
<option value="0" hidden>City...</option>
<option value="775">Tbilisi</option>
<option value="776">Kutaisi</option>
<option value="788">Batumi</option>
and so on...


Now I need, when I will call this selection
'region'
in PHP and then insert value in MySQL.

For example: Someone choose Tbilisi (i.e.
$_POST['region']=775
) and this value (775) goes to DB. I need, PHP choose from HTML equivalent of this value and instead 775 in DB insert TBILISI...

any clue?

Thanks in advance...

Answer

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']];