pravonline Posted May 18, 2006 Share Posted May 18, 2006 Dear All,My requirement is to list out the databases from our localhost server along with a radio button for each database, I need to allow the user to select any one database through radiobutton and the selected database name has to be passed on to the next php script, since i'm new to this PHP environment, need your guidance please, Thanks in advance,The sample code is as follows:[code]<html> <head> <title>PHP Test</title> </head><body> <?phprequire_once 'DB.php'; // must be included in any script that uses PEAR::DB$db_host = "localhost"; // hostname of the database server$db_user = "root"; // database user's username$db_pass = ""; // database user's password, nothing by default//$db_name = "economy"; // the name of the database to connect to$db_type = "mysql"; // the type of database server.// your data source name string. This contains the connection// information for your database.$dsn = "$db_type://$db_user:$db_pass@$db_host/$db_name";// creates a database connection object or a database error// object based on the success of the database connection.$db = DB::connect($dsn, TRUE);// if an error was encountered, the script exits with an error messageif (DB::isError($db)) { die($db->getMessage());}$tabelle = $cricket."cpu"; // SQL query that you wish to use to query the database$sql1 = "SHOW DATABASES";//$sql = "SELECT * from cricket";if (!$result = MYSQL_QUERY($sql1)) {print ERR_SQL.$tabelle; exit;} else {if (mysql_num_rows($result) > 0) {while ($row=mysql_fetch_row($result)) { foreach ($row as $col=>$val) foreach ($row as $col=>$val2) { ?><P><input type=radio name="locf" VALUE="$val"><?phpprint $val; } } } else {print ERR_NULL.$tabelle; exit;} } ?><form action="subpgm.php" method="post"><P><INPUT TYPE=submit VALUE="Validate it!"></P></form></body></html>[/code]In the above program, i was supposed to get the selected database name in the variable called "locf", but no value is storing in that variable, can anyone throw some light on that, Thank you Quote Link to comment https://forums.phpfreaks.com/topic/9912-radio-button-in-php/ Share on other sites More sharing options...
samshel Posted May 18, 2006 Share Posted May 18, 2006 As for as i see... there are a couple of issues with this code1) the form tag should be before radio button. it should be after the body tag,2) <input type=radio name="locf" VALUE="$val"> - in this it should be <input type=radio name="locf" VALUE="<?php echo $val;?>">hth Quote Link to comment https://forums.phpfreaks.com/topic/9912-radio-button-in-php/#findComment-36849 Share on other sites More sharing options...
pravonline Posted May 19, 2006 Author Share Posted May 19, 2006 Dear Samshel,Thanks for your comments, I reworked the coding as per your advice and it worked perfectly, Thanks to you once again,Regards,Praveen Quote Link to comment https://forums.phpfreaks.com/topic/9912-radio-button-in-php/#findComment-37086 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.