PHP ComboBox Retrieve value

Alles, was PHP betrifft, kann hier besprochen werden.

PHP ComboBox Retrieve value

Postby lunaticbit » 04. September 2015 09:21

Dear Friends. I'm trying to find a way to retrive a value from a MSQL Table using a Combo Box on a PHP page. Table " firms" has two columns only: Id and Descr. The way to populate the contents is as follows:
Code: Select all

<?php
mysql_connect('localhost', 'root', '');
   mysql_select_db('test');
   $sql = "select descr from firm order by id";
   $records = mysql_query($sql) or die(mysql_error());
echo "<select>";
while($row = mysql_fetch_array($records))
{
   echo "<option value='".$row['descr']."'>".$row['descr']."</option>";
}
echo "</select>";
echo "<br>";
mysql_free_result($records);
?>



I want to retrieve the selected value into a variable for further proccessing.
Thank you in advance - Nic
lunaticbit
 
Posts: 21
Joined: 09. April 2015 16:24
Operating System: Windows 7

Re: PHP ComboBox Retrieve value

Postby JJ_Tagy » 04. September 2015 13:48

The php error log may show you any problems. The only thing I see is that you said the table is "firms" but you have "firm" in your query.
JJ_Tagy
 
Posts: 788
Joined: 30. January 2012 13:44
XAMPP version: 5.5.15
Operating System: Windows 10 Pro x64

Re: PHP ComboBox Retrieve value

Postby Nobbie » 04. September 2015 15:50

You have to apply a name-TAG for the Select Box, otherwise PHP will not provide an appropriate value in $_POST. There is also missing a form, this is only a fragment, not valid code.

You should read some tutorials about HTML and Forms and CGI/PHP. We cannot replace the need for reading documentation.
Nobbie
 
Posts: 13165
Joined: 09. March 2008 13:04

Re: PHP ComboBox Retrieve value

Postby lunaticbit » 15. September 2015 10:17

Sorry for my poor skill.
The above mentioned code was only to populate the combo box generates from a mysql table. I was aiming to gain some assistance for my education skills.
Suppose that I have to update to:
<select firm_value> label
and then forward
$firm_value = $_GET['firm_value]; after
thank you for your help

update -> As far it concerns the table name FIRM or FIRMS the module works ok with the FIRM table name
lunaticbit
 
Posts: 21
Joined: 09. April 2015 16:24
Operating System: Windows 7

Re: PHP ComboBox Retrieve value

Postby lunaticbit » 23. October 2015 10:00

The Ptoblem hass been solved
lunaticbit
 
Posts: 21
Joined: 09. April 2015 16:24
Operating System: Windows 7


Return to PHP

Who is online

Users browsing this forum: No registered users and 35 guests