radio button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanjay123456
    New Member
    • Sep 2006
    • 125

    radio button

    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'><i nput

    type='radio' name='quiz'
    value='1' /></td><td><?php echo
    $row['op1'];?><br></td></tr><tr><td
    valign='top'><i nput
    type='radio' name='quiz'
    value='2' /></td><td><?php echo
    $row['op2'];?><br></td></tr><tr><td
    valign='top'><i nput
    type='radio' name='quiz'
    value='3' /></td><td><?php echo
    $row['op3'];?><br></td></tr><tr><td
    valign='top'><i nput
    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><ti tle>Questionnai re</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
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    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]

    Comment

    • sanjay123456
      New Member
      • Sep 2006
      • 125

      #3
      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

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        I'm sorry sanjay, I don't quite understand your problem. Could you try rewording your question differently?

        Comment

        • sanjay123456
          New Member
          • Sep 2006
          • 125

          #5
          Dear motama


          my complete code is below

          [PHP]

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

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

          //start mysql connection

          $con = mysql_connect(" localhost","roo t","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_arr ay($r))
          //while($_SESSION['count'] <<3)
          {?>

          style="color: #0000ff"><?php echo
          $row['que'];?><table border='0'><tr> <td valign='top'><i nput
          type='radio' name='quiz' value='1' /></td><td><?php echo
          $row['op1'];?><br></td></tr><tr><td valign='top'><i nput
          type='radio' name='quiz' value='2' /></td><td><?php echo
          $row['op2'];?><br></td></tr><tr><td valign='top'><i nput
          type='radio' name='quiz' value='3' /></td><td><?php echo
          $row['op3'];?><br></td></tr><tr><td valign='top'><i nput
          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_arr ay($r2))
          {
          $counter=$ro['total_que'];

          if($counter==$_ SESSION['count'])
          {

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

          } //end of while loop

          // store the user answer in database

          $que=$_POST['que'];

          $quiz=$_POST['quiz'];

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

          //close mysql connection
          mysql_close($co n);

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

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
          <html><head><ti tle>Questionnai re</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

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            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.p hp">
            ....
            ....
            </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]

            Comment

            • sanjay123456
              New Member
              • Sep 2006
              • 125

              #7
              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

              Comment

              • Motoma
                Recognized Expert Specialist
                • Jan 2007
                • 3236

                #8
                Originally posted by sanjay123456
                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.

                Comment

                • ashith
                  New Member
                  • Feb 2007
                  • 8

                  #9
                  Am new 2 .Net C# i need d details of tat..

                  Comment

                  • Motoma
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3236

                    #10
                    Originally posted by ashith
                    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.

                    Comment

                    Working...