Jump to content

Radio button in PHP


pravonline

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
Link to comment
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
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.