kekagiso Posted March 2, 2006 Share Posted March 2, 2006 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/3940-retrieving-combo-box-value/ Share on other sites More sharing options...
zq29 Posted March 2, 2006 Share Posted March 2, 2006 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 Link to comment https://forums.phpfreaks.com/topic/3940-retrieving-combo-box-value/#findComment-13706 Share on other sites More sharing options...
kekagiso Posted March 3, 2006 Author Share Posted March 3, 2006 [!--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 Quote Link to comment https://forums.phpfreaks.com/topic/3940-retrieving-combo-box-value/#findComment-13855 Share on other sites More sharing options...
zq29 Posted March 3, 2006 Share Posted March 3, 2006 [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 Link to comment https://forums.phpfreaks.com/topic/3940-retrieving-combo-box-value/#findComment-13988 Share on other sites More sharing options...
kekagiso Posted March 4, 2006 Author Share Posted March 4, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/3940-retrieving-combo-box-value/#findComment-14235 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.