Jump to content

Archived

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

pravonline

Radio button in PHP

Recommended Posts

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>

<?php
require_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 message
if (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">




<?php

print $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

Share this post


Link to post
Share on other sites
As for as i see... there are a couple of issues with this code

1) 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

Share this post


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

Share this post


Link to post
Share on other sites

×

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.