Jump to content

retrieving combo box value


kekagiso

Recommended Posts

I want to get the selected value from my combo box and save in mysql database. I dont even no how to begin, I've managed to create the combo box. Here is my code:

<?
include("dbinfo.inc.php");

class ComboBox
{
var $tableName;
var $databaseName;


/* Begin Edit Constructor */

function ComboBox( $tblname, $dbname )
{
$tableName = $tblname;
$database = $dbname;


/* Connect to database */
mysql_connect('127.0.0.1',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$para_query=mysql_query("select * from $tableName") or die(mysql_error());


/* Begin result table */
echo("<table width=100>");
echo("<select size=\"1\" name=\"id\">");
while ($row = mysql_fetch_array($para_query))
{
/* Output combo box */
echo("<option value=");
echo( $row[ 0 ] );
echo(">");
echo( $row[ 0 ] );
echo("</option>");
}

echo("</select>");
echo("</table>");

}// End Constructor

}// End Edit

?>
Link to comment
https://forums.phpfreaks.com/topic/3940-retrieving-combo-box-value/
Share on other sites

[!--quoteo(post=351128:date=Mar 3 2006, 12:04 AM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Mar 3 2006, 12:04 AM) [snapback]351128[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You need to enclose your <select> fields in a form and POST it to another script to process (or POST it back to itself and do it all in the same script). Are you familiar with HTML forms?
[/quote]


I'm new to both HTML and PHP. I've spend the whole of yesterday searching for a solution. I'l be glad if you can assist. I know I'm left with that part that allows me to retrieve the selected value.

Thank you in advance
[code]//HTML Form
<form name='data_collect' action='process.php' method='POST'>
    Pick a number:
    <select name='number'>
        <option value='0'>0</option>
        <option value='1'>1</option>
        <option value='2'>2</option>
    </select>
    <input type='submit' name='submit' value='Go!'/>
</form>

//PHP Processing script
<?php
$number = $_POST['number'];
echo "The number you selected was: $number";
?>[/code]
[!--quoteo(post=351417:date=Mar 3 2006, 10:17 PM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Mar 3 2006, 10:17 PM) [snapback]351417[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]//HTML Form
<form name='data_collect' action='process.php' method='POST'>
    Pick a number:
    <select name='number'>
        <option value='0'>0</option>
        <option value='1'>1</option>
        <option value='2'>2</option>
    </select>
    <input type='submit' name='submit' value='Go!'/>
</form>

//PHP Processing script
<?php
$number = $_POST['number'];
echo "The number you selected was: $number";
?>[/code]
[/quote]


Thanx a lot. I will try to modify my script using this one as a guide. My list box is a dynamic one as you might have seen.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.