By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,046 Members | 1,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,046 IT Pros & Developers. It's quick & easy.

radio button

sanjay123456
100+
P: 125
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
Share this Question
Share on Google+
9 Replies


Motoma
Expert 2.5K+
P: 3,235
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
100+
P: 125
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
Expert 2.5K+
P: 3,235
I'm sorry sanjay, I don't quite understand your problem. Could you try rewording your question differently?
Feb 5 '07 #4

sanjay123456
100+
P: 125
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
Expert 2.5K+
P: 3,235
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
100+
P: 125
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
Expert 2.5K+
P: 3,235
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

P: 8
Am new 2 .Net C# i need d details of tat..
Feb 6 '07 #9

Motoma
Expert 2.5K+
P: 3,235
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

Post your reply

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