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
Share on other sites

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?
Link to comment
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
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

[!--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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.