Hello everyone, such a question. There is a DB with 1 table and 5 columns, and there are 2 pages.

DB

here is Index pp

<? $db_host = 'localhost'; $db_name = 'figures'; $db_username = 'root'; $connect_to_db = mysql_connect($db_host, $db_username, $db_password) or die("Не найдено соединение: ".mysql_error()); mysql_select_db($db_name, $connect_to_db) or die("Не найдена бд: ".mysql_error()); echo "<form method='post' action='obj.php'><select name='id'>"; for ($i = 1; $i <= 1000; $i++) { $sql = mysql_query("select * from `figures` where `id`='".$i. "' order by `about Obj`"); while ($s = mysql_fetch_array($sql)) { echo "<option value='".$s['id']. "'>".$s['about Obj']. "</option>"; } $sec = $s['id']; echo "<br>"; } echo "</select> <input type='submit' name='action' value='Выбрать'> </form>"; ?> 

here is the page receiving code

  $connect_to_db = mysql_connect($db_host, $db_username, $db_password) or die("Не найдено соединение: " . mysql_error()); mysql_select_db($db_name, $connect_to_db) or die("Не найдена бд: " . mysql_error()); $sec1=$_POST['sec']; if(isset ($_POST['action'])){ $sql=mysql_query("select * from `figures` where `id`='".$sec1."'"); while ($data1 = mysql_fetch_array($sql)) { echo $data1['obj']; } } 

I need to transfer the selected id from the obj column to the selected id and write it to the variable, but something doesn't work, tell the experienced eye what is wrong and what to fix. Thank you in advance!

  • но что то не получается - what exactly? gives an error? Or records 1,000 lines at once or locks in the bathroom and spends hot water in vain? - Alexey Shimansky
  • check for everyone if isset $ _POST ['sec'] &&! empty $ _POST ['sec'] - Jean-Claude
  • @ AlekseyShimansky just doesn’t pass the obj value of the corresponding id, and 1 to 1000, I just don’t remember the function that goes through the database until the end)) - Michael
  • In my opinion the problem is the $ _POST mismatch. you have a form with the name = 'id' element, and you accept $ _POST ['sec'] - Jean-Claude
  • @ Jean-Claude $ sec1 = $ _ POST ['id'] - Michael

1 answer 1

You fill the select with the name id

<select name='id'>

And read from the sec variable

$sec1=$_POST['sec'];

Synchronize both names

  • @ Anton Shchyrov $ sec1 = $ _ POST ['id']; - Michael
  • @MichaelBocharov yes - Anton Shchyrov
  • Everything is transmitted but only is assigned an id at the end, how to remove? - Michael