V
V
Vlad Kolegov2015-05-26 19:14:21
PHP
Vlad Kolegov, 2015-05-26 19:14:21

Dropdown list in PHP+ problem with encoding and implementation of POST method?

There is a drop down list which is filled by request. When changing the encoding of the file itself, it turns out either like this, but the Cyrillic alphabet is displayed normally in the drop-down list: f0225121c3a84294aa79b97757558725.JPG
Or so, everything is fine, except for the list itself: aad0369dcb6142ebbeb884c4f1de09da.jpg
Changing the encoding in IIS did not help. I still can't figure out how to send a request without the "select" button, And still I can implement so that when selecting from the list from the database, data is pulled out, which, moreover, should be displayed not as one variable, but as several, each cell. (To then enclose them in hyperlinks to go to other pages). Yes, and POST does not work for me for some reason to display an entire column from the table to the page.

<html>
<?php
$servername = "VLADISLAV-ПК\SQLEXPRESS"; 
$uid = "Vlad";   
$pwd = "Aa1";  
$databaseName = "TDM";
$connectionInfo = array("UID"=>$uid, "PWD"=>$pwd, "Database"=>$databaseName);
$dbcon = sqlsrv_connect($servername, $connectionInfo);

?>
<div id="content"> 

    
    <form action="" method="POST">
        <select name="UID_OU" size="1">
        <option value="0" selected="selected">Выберите учреждение:</option>
<?php
        
    // Запрос к БД для вывода данных в select   
    $query = "SELECT * FROM spr.OU";
    
    // Выполняем запрос к БД
    $result = sqlsrv_query($dbcon, $query);
    
    // При ошибке запроса
    if ( !$result ) die ( mysql_error() );
    
    // В цикле выводим данные в OPTION
    while ($row = sqlsrv_fetch_array($result))
    {
    if(!($row[0] === '')){
        echo "<option value='".$row['UID_OU']."'>".$row['Name_Sokr']."</option>";
    }
    }
 
  ?>

        </select></br>
        <input type="submit" value="Выбрать"/>      
    </form>
  <?php   
    // Если отсутствует $_POST['UID_OU']    
    if(isset($_POST['UID_OU']))
    {
    // Номер учреждения
        $UID_OU = $_POST['UID_OU'];
        
        // Выбираем соответствующие данные из БД
        $que = "SELECT * FROM spr.FGOS where NameFgos='$UID_OU'";
        
        // Делаем запрос к БД
        $res = sqlsrv_query($dbcon, $que);
    
        // При ошибке запроса
        if ( !$res ) die ( sqlsrv_error() );
        
        // В цикле выводим данные
        while ( $res_lab = sqlsrv_fetch_array($res) )
        {
      echo $res_lab['NameFgos'];
        }
    }
    else
    {
    echo"<p>Учреждение не выбрано.</p><br>";
    }
  sqlsrv_close($dbcon);
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Andrienko, 2015-05-26
@EvolMate

Most likely, the trouble occurs with the storage and retrieval of Cyrillic data from the database.
In what encoding is the data in the table stored?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question