Jump to content


Photo

retrieving combo box value


  • Please log in to reply
4 replies to this topic

#1 kekagiso

kekagiso
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 02 March 2006 - 08:44 PM

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

?>

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 02 March 2006 - 10:04 PM

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?

#3 kekagiso

kekagiso
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 03 March 2006 - 09:39 AM

[!--quoteo(post=351128:date=Mar 3 2006, 12:04 AM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Mar 3 2006, 12:04 AM) View Post[/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

#4 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 03 March 2006 - 08:17 PM

//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";
?>


#5 kekagiso

kekagiso
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 04 March 2006 - 07:34 PM

[!--quoteo(post=351417:date=Mar 3 2006, 10:17 PM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Mar 3 2006, 10:17 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
//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";
?>
[/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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users