473,836 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Clarification about Radio button in php

34 New Member
hiii
i have a form within which i have 3 radio button with same name but value will be retrieved from the mysql database.But each radio button will do different actions.can plz suggest me some way.
Aug 11 '06 #1
17 14320
ronverdonk
4,258 Recognized Expert Specialist
What are the fields fromMySql that you get the values from. In order to populate all three button texts with diferent values you'll have to have 3 fields in your data base. And is there a default value to be set to 'checked=checke d'?

Ronald :cool:
Aug 11 '06 #2
hemashiki
34 New Member
i'm retrieving 3 fields(values) from mysql,for this,i'm having 3 radio buttons having same names,when i checked,each must do different operations,no default checking...but when i check ,all the 3 radio buttons doing same operation,how can i check...
Aug 11 '06 #3
ronverdonk
4,258 Recognized Expert Specialist
Please show the code you have until now regarding those radio buttons. It is somewhat difficult to react to this problem without seeing the code involved.

Ronald :cool:
Aug 11 '06 #4
hemashiki
34 New Member
<?php
mysql_connect(" localhost","roo t","");
mysql_select_db ("asc");
$q=mysql_query( "select * from course");
print '<form action="a.php" method="get">';
while($q1=mysql _fetch_array($q ))
{
print '<input type="radio" name="op">';
print $q1[name];
}

print '<input type="Submit">' ;
print '</form>';
?>

In this name is the only one field in the table "course."
And i have three values for this field in mysql database.so that three radio buttons will have the value from the table "course"whi ch is in mysql database.
Now if i select different radio button it must do different actions.Since i have used while loop to get the value of radio button I have a problem in accessing each radio button.
Aug 12 '06 #5
ronverdonk
4,258 Recognized Expert Specialist
Now the following code works. What I did is assign the SQL row value from column 'name' to the 'value=' attribute of the <input and to display the same 'name' at the end of the <input statement, so it displays next to the radio button.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (isset($_GET['op'])) {
  3.   print_r($_GET);
  4.   die;
  5. }
  6. else {
  7.    mysql_connect("localhost","ronverdonk","ronnie09");
  8.    mysql_select_db("vwso");
  9.    $q=mysql_query("select * from course");
  10.    print '<form action="a.php" method="get">';
  11.    while($q1=mysql_fetch_array($q)) {
  12.       print "<input type='radio' name='op' value='".$q1['name']."'>".$q1['name']."<br />";
  13.    } 
  14.    print '<input type="Submit" value="Send it!">';
  15.    print '</form>';
  16. }
  17. ?> 
Ronald :cool:
Aug 12 '06 #6
hemashiki
34 New Member
Now the following code works. What I did is assign the SQL row value from column 'name' to the 'value=' attribute of the <input and to display the same 'name' at the end of the <input statement, so it displays next to the radio button.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (isset($_GET['op'])) {
  3.   print_r($_GET);
  4.   die;
  5. }
  6. else {
  7.    mysql_connect("localhost","ronverdonk","ronnie09");
  8.    mysql_select_db("vwso");
  9.    $q=mysql_query("select * from course");
  10.    print '<form action="a.php" method="get">';
  11.    while($q1=mysql_fetch_array($q)) {
  12.       print "<input type='radio' name='op' value='".$q1['name']."'>".$q1['name']."<br />";
  13.    } 
  14.    print '<input type="Submit" value="Send it!">';
  15.    print '</form>';
  16. }
  17. ?> 
Ronald :cool:

I am having "a.php" which must be called when submit button is clicked.And it must do the operation based on the radio button selected.
for eg:
if the values of radio buttons are:

Orientation programme
Refresher course
Need based course.
Which are retrieved from the database.

And if i select the radio button with value Orientation Programme the op1.php must be called.And if i select a radio button with value Refresher Course the rc1.php must be called etc.So how can i include that in the "a.php" coding


This is my coding for "a.php"

<?php
mysql_connect(" localhost","roo t","") or die("connection errro");
mysql_select_db ("asc") or die("Database Error");
$s=$_GET['op'];
$sel=mysql_quer y("select * from opgm") or die("Table Error");
if($_GET['op']) /*I struck here how to get the value of selected radio button value from check.php.*/
{
include("op1.ph p");
}
if($_GET['op'])
{
include("rc1.ph p");
}
?>


Thank u
Aug 13 '06 #7
ronverdonk
4,258 Recognized Expert Specialist
First, it is probably better to include the name of the routine, belonging to a particular value, e.g. rc1.php with Refresher Course, in the data base entry. That way it will be a lot easier to change and you don't have to hardcode anything in your code, but just pick the button codes and the routines from the database.

Anyway, the following is the code as it works. I have included A.PHP, RC1.PHP, OP1.PHP and QQ1.PHP. Also the setup of the table 'course' is in the a.php code.
Expand|Select|Wrap|Line Numbers
  1. A.PHP:
  2. <?php
  3. /*
  4.    THIS IS THE TEST TABLE:
  5.    create table course (id int(2) primary key auto_increment, name varchar(25));
  6.    insert course values (1,'Orientation Programme');
  7.    insert course values (2,'Refresher Course');
  8.    insert course values (3,'Need based course');  
  9. */
  10. if (isset($_GET['op'])) {
  11.   switch ($_GET['op']) {
  12.     case 'Orientation Programme':
  13.         header('Location: op1.php');
  14.         break;
  15.     case 'Refresher Course':
  16.         header('Location: rc1.php');
  17.         break;
  18.     case 'Need based course':
  19.         header('Location: qq1.php');
  20.         break;
  21.     default :
  22.         echo "You have selected an invalid value";
  23.         break;
  24.   } // end switch
  25. } // end if (isset
  26.  
  27. else {
  28.    mysql_connect("localhost","ronverdonk","ronnie09");
  29.    mysql_select_db("vwso");
  30.    $q=mysql_query("select * from course");
  31.    print '<form action="a.php" method="get">';
  32.    while($q1=mysql_fetch_array($q)) {
  33.       print "<input type='radio' name='op' value='".$q1['name']."'>".$q1['name']."<br />";
  34.    } 
  35.    print '<input type="Submit" value="Send it!">';
  36.    print '</form>';
  37. }
  38. ?>
  39. OP1.PHP:
  40. <?php
  41. echo 'You are in op1.php';
  42. exit;
  43. ?>
  44.  
  45. RC1.PHP:
  46. <?php
  47. echo 'You are in rc1.php';
  48. exit;
  49. ?>
  50.  
  51. QQ1.PHP:
  52. <?php
  53. echo 'You are in qq1.php';
  54. exit;
  55. ?>
Ronald :cool:
Aug 13 '06 #8
hemashiki
34 New Member
Thanks for your coding, it was very useful but in the switch case:

case 'orientation programme': //This should not be static it should be dynamic that is,the value of the radio button should be compared with the value in the database.
Aug 14 '06 #9
ronverdonk
4,258 Recognized Expert Specialist
First, it is probably better to include the name of the routine, belonging to a particular value, e.g. rc1.php with Refresher Course, in the data base entry. That way it will be a lot easier to change and you don't have to hardcode anything in your code, but just pick the button codes and the routines from the database.
Well, see my above note from yesterday. You know what to change now in you database and code. Good luck.

Ronald :cool:
Aug 14 '06 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3285
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1> <input type="radio" name=p2 value=2> <input type="radio" name=p2 value=3> then a text area and a button:
5
3115
by: Digital Puer | last post by:
I have the following HTML form: - radio button A (default selected) - radio button B - input field, of type "file" with "Choose" button - submit button I would like to have it so that if the user clicks on the "Choose" button of the input field (to select a file on the local disk), then radio button B is automatically
3
3138
by: John Davis | last post by:
I created a ASP.NET Web Form using VB.NET with a text box, 2 radio buttons. When the user click the first radio button, the text will change to uppercase. If the user clicks the other radio button, the text will change to lowercase. I added the following event, but still won't able to change the text to uppercase. Private Sub RadioButton1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
3
2075
by: Amelyan | last post by:
When we want radio button to belong to a group name we say, radio1.GroupName="GroupA". In this case, radio1 will be unselected if another radio button is selected in "GroupA". Is there a way (trick, custom RadioButton, or javascript) to make radio button (radio1) belong to 2 independent radio button groups instead of one? This would be an equivalent of sayting something like radio1.GroupName1 = "GroupA"; radio1.GroupName2 = "GroupB";
8
5907
by: David Cameron | last post by:
I noticed that using an HTMLInputRadioButton and specifying a value to be an empty string (""), this is overridden by ASP.Net which set the value of the control to be the same as the ID of the control. See the code below * Page.aspx: <%@ Page language="c#" Codebehind="Test.aspx.cs" AutoEventWireup="false" Inherits="Webspace.Test" %>
1
2985
by: Joe Attardi | last post by:
Hi all, On a form on one of my pages I have two <select> elements, and each one is paired up with a radio button. The idea is to choose an item from one list or the other and select the radio button of the list you want to use. I'm using JavaScript to automatically select the radio button corresponding to a list when you click on the list (using the onclick event handler). Is that the best event to change on, or should this
9
2256
by: IchBin | last post by:
I can not see what the problem is with this script. I am just trying to set a radio button by calling setCheckedValue('abbr_letter', 'V'). Sorry I am new to javascript. <html> <head> <script type="text/javascript"> function setCheckedValue(radioObj, newValue) { if(!radioObj)
10
6112
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
8
4619
by: photoboy | last post by:
I have racked by brain long enough on this, so now I need the help of someone who knows what they are doing. Here is what I am trying to achieve: First, I have two radio buttons (both unchecked) that need to be validated when the submit button is clicked. Instead of the standard alert window popping up (which I have now), I want the radio button background color to change from the table color (E2E2E2) to red (FF0000) for both buttons...
0
9816
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9668
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10840
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10588
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6978
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5647
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4448
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.