Dropdown list with database data

From the database, the data comes into the select field. Users select the required category, this value is entered into the database. Can someone post some code on how to do this? For clarity.

And how to check the text field for the correctness of the entry? Like just numbers? Only Russian letters and so on? without downloading additional plugins.

Answer 1, authority 100%


        <label class="description" for="idpersa"></label>
            <select name="idpersa">
<option value="" selected="selected"></option>
$result=mysql_query("SELECT id, name FROM characters WHERE account = $myrow2[id] ORDER BY name");
while($table = mysql_fetch_array($result))
    echo "<option value='".$table["id"]."' >".$table["name"]." </option>";

The select handler is normal:

if (isset($_POST['idpersa'])) {$idpersa = $_POST['idpersa'];}
$idpersa = stripslashes($idpersa);
$idpersa = htmlspecialchars($idpersa);
settype($idpersa,'int'); //   , .

Well, then you just enter it into the database:

$query = "INSERT into tablename (id   ) VALUES ('$idpersa',     )";
$result = mysql_query($query) or die(mysql_error());;