473,387 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

radio button

sanjay123456
125 100+
Dear Friends ,

i have i problem that let say suppose i am working in index.php

and
[PHP]
<form name="myform" method="POST"
action="<?php echo
$_SERVER['PHP_SELF']; ?>
">
[/PHP]

means that its call again index.php

and i wanna that on the same page (INDEX.PHP) i have radio buttton and client side user click any of one radio button and then its goes to database and insert it how can i write and how can i write $_ post which is right place for this

following code for radio button

[PHP]

<h3><p style="color: #0000ff"><?php echo
$row['que'];?><table
border='0'><tr><td valign='top'><input

type='radio' name='quiz'
value='1' /></td><td><?php echo
$row['op1'];?><br></td></tr><tr><td
valign='top'><input
type='radio' name='quiz'
value='2' /></td><td><?php echo
$row['op2'];?><br></td></tr><tr><td
valign='top'><input
type='radio' name='quiz'
value='3' /></td><td><?php echo
$row['op3'];?><br></td></tr><tr><td
valign='top'><input
type='radio' name='quiz'
value='4' /></td><td><?php echo
$row['op4'];?><br></td></tr></table><br></p></h3>
[/PHP]

following code for form action

[PHP]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Questionnaire</title></head>
<body>
<form name="myform" method="POST"
action="<?php echo
$_SERVER['PHP_SELF']; ?>
">
<input type="submit" VALUE="NEXT"
/>
<input type="hidden" name="submitted"
value="1" />
<input type="hidden" name="que"
value="<?=$row[
'que']?>">
</form></body></html>
[/PHP]

sanjay
Feb 5 '07 #1
9 3835
Motoma
3,237 Expert 2GB
If I am totally clear with what you are asking, you would do:
[PHP]
if(isset($_POST['quiz']))
{
//do form validation and
//quiz inserts here.
}
[/PHP]
Feb 5 '07 #2
sanjay123456
125 100+
i have this thing my problem is that how can i radio button on the same page
and what is syntax of form action

sanjay
Feb 5 '07 #3
Motoma
3,237 Expert 2GB
I'm sorry sanjay, I don't quite understand your problem. Could you try rewording your question differently?
Feb 5 '07 #4
sanjay123456
125 100+
Dear motama


my complete code is below

[PHP]

<?php
session_start();
if (!isset($_SESSION['count']))

$_SESSION['count'] = 1;
if (isset($_POST['submitted'])) {

//start mysql connection

$con = mysql_connect("localhost","root","123456");

if (!$con)
{
die('Could not connect: ' . mysql_error());
}

//select mysql database

mysql_select_db("my_db", $con);

//Select Question in to database

$sql="select * from quest where count = ".$_SESSION['count']."";

// run query
$r=mysql_query($sql);

if (!r)
{
die('Error: ' . mysql_error());
exit();
}

//fetch the data from database by loop

while($row = mysql_fetch_array($r))
//while($_SESSION['count'] <<3)
{?>

style="color: #0000ff"><?php echo
$row['que'];?><table border='0'><tr><td valign='top'><input
type='radio' name='quiz' value='1' /></td><td><?php echo
$row['op1'];?><br></td></tr><tr><td valign='top'><input
type='radio' name='quiz' value='2' /></td><td><?php echo
$row['op2'];?><br></td></tr><tr><td valign='top'><input
type='radio' name='quiz' value='3' /></td><td><?php echo
$row['op3'];?><br></td></tr><tr><td valign='top'><input
type='radio' name='quiz' value='4' /></td><td><?php echo
$row['op4'];?><br></td></tr></table><br></p></h3>
<?php
}

//Query for check END Of the test paper

$q1="select * from sub_stat";

$r2=mysql_query($q1);

while($ro = mysql_fetch_array($r2))
{
$counter=$ro['total_que'];

if($counter==$_SESSION['count'])
{

?>
// Call finish page For result
<a href="http://localhost/finish.php">FINISH</a>
<?php
}

} //end of while loop

// store the user answer in database

$que=$_POST['que'];

$quiz=$_POST['quiz'];

mysql_query("INSERT INTO result(que,ans)
VALUES ('$que', '$quiz')");

//close mysql connection
mysql_close($con);

$_SESSION['count'] += 1;
}?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Questionnaire</title></head>
<body>
<form name="myform" method="POST" action="<?php echo
$_SERVER['PHP_SELF']; ?>">
<input type="submit" VALUE="NEXT"/>
<input type="hidden" name="submitted" value="1" />
<input type="hidden" name="que" value="<?=$row['que']?>">
</form></body></html>

[/PHP]


ok and i wanna that user click on any 4 option and its goes to reslut table


sanjay
Feb 5 '07 #5
Motoma
3,237 Expert 2GB
If the problem you are having is that you want to go to a different page when the user clicks the submit button, then all you need to do is set your FORM ACTION to the php page to handle the submit:
[HTML]
<FORM ACTION="table.php">
....
....
</FORM>
[/HTML]

If you want the page to immediately switch when the user clicks the radio button, this belongs in the Javascript forum.

If you want to display something different when the page submits, but have it remain the same php file, then:
[PHP]
if(isset($_POST['quiz']))
{
//Put all code and formatting to be done after the submit here
}
else
{
//Put all code and formatting to create the form here
}
[/PHP]
Feb 5 '07 #6
sanjay123456
125 100+
Dear motoma ,

my problem is that in front side user having four option and user click any one of them

and after that he click the next button again he ask four choice

so i want to send this option value on the same php from where option r print on page (index.php ) how i write for this code ?
means this is online examination form where question and option r same page and collect answer on the same page and i wanna that this option value is stored in database

plz help me ?

sanjay
Feb 6 '07 #7
Motoma
3,237 Expert 2GB
Dear motoma ,

my problem is that in front side user having four option and user click any one of them

and after that he click the next button again he ask four choice

so i want to send this option value on the same php from where option r print on page (index.php ) how i write for this code ?
means this is online examination form where question and option r same page and collect answer on the same page and i wanna that this option value is stored in database

plz help me ?

sanjay
Take a look at the last segment of code on my last post. Adding that to your code will help you accomplish what you have described.
Feb 6 '07 #8
ashith
8
Am new 2 .Net C# i need d details of tat..
Feb 6 '07 #9
Motoma
3,237 Expert 2GB
Am new 2 .Net C# i need d details of tat..
ashith, you are in the wrong forum. Please post a question in the .NET forum.
Feb 6 '07 #10

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

Similar topics

4
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>...
5
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...
3
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,...
3
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...
8
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...
1
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...
9
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...
10
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...
0
by: jehugaleahsa | last post by:
Hello: I have radio buttons bound to boolean properties in a business object. private void bindRadioButton(RadioButton button, string propertyName) { Binding binding =...
8
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)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.