need help in coding

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajani gupta
    New Member
    • Sep 2006
    • 5

    need help in coding

    Hi i have this code to generate radio buttons in group

    [PHP]echo "<b>$j.</b><b>&nbsp;$Que s</b><p><table class='text'><t r><td><input type=radio value=a name=$Q_ID></td><td>$opt1</td></tr><tr><td ><input type=radio value=b name=$Q_ID></td><td>$opt2</td></tr><tr><td><inp ut type=radio value=c name=$Q_ID></td><td >$opt3</td></tr><tr><td ><input type=radio value=d name=$Q_ID></td><td>$opt4</td></tr></table><p><hr>";
    [/PHP]

    now i want to get the value of checked radio buttons to b inserted in the data base for these radio buttons.
    plz help me as soon as possible,
    Last edited by Niheel; Sep 5 '06, 07:15 AM.
  • vssp
    Contributor
    • Jul 2006
    • 268

    #2
    Get the value $_POST method and store the table




    Thanks
    vssp

    Comment

    • rajani gupta
      New Member
      • Sep 2006
      • 5

      #3
      thanx for your reply i m fresher in php.can u send the complete code to me that hw the value will be fetched and stored on the basis of the code which i have send to u before.

      thanx.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Firstly, put your code within PHP tags. Maybe more people would look at it!

        Secondly, are you expecting a complete program based on the minimal statements you displayed in your thread? You should at least have shown a working <form> and more detail on db use.

        Ronald :cool:

        Comment

        • vbsourcer
          New Member
          • Aug 2006
          • 17

          #5
          I agree ronald. HERE HERE..
          Please enlighten us a bit more.

          Comment

          • rajani gupta
            New Member
            • Sep 2006
            • 5

            #6
            hi thanx for concerning my problem here this is a block of code i m sending plz check it and send me the code to fetch the value of selected radio buttons and store that to database
            [PHP] <?
            mysql_connect(l ocalhost,$user, $password);
            @mysql_select_d b($database) or die( "Unable to select database");
            $query="SELECT * FROM Question WHERE Sec_ID = 'H01' ORDER BY RAND( ) ";
            $result=mysql_q uery($query);
            $num=mysql_numr ows($result);
            mysql_close();

            //echo "<b><center>HIS TORY TEST: [ $num ] Questions</center></b><br>Duration : 2 Hrs<br><br>";
            echo "<b><center>HIS TORY TEST:Duration: 2 Hrs</center></b><br><br>";
            $i=0;
            $j=1;

            while ($i < $num) {
            $Q_ID=mysql_res ult($result,$i, "Q_ID");
            $Ques=mysql_res ult($result,$i, "Ques");
            $opt1=mysql_res ult($result,$i, "opt1");
            $opt2=mysql_res ult($result,$i, "opt2");
            $opt3=mysql_res ult($result,$i, "opt3");
            $opt4=mysql_res ult($result,$i, "opt4");
            $Qtype=mysql_re sult($result,$i ,"Qtype");
            echo "<b>$j.</b><b>&nbsp;$Que s</b><p><table class='text'><t r><td>$b<br>$c< br>$d<br>$e</td></tr></table><table class='text'><t r><td><input type=radio value=a name=$Q_ID></td><td>$opt1</td></tr><tr><td ><input type=radio value=b name=$Q_ID></td><td>$opt2</td></tr><tr><td><inp ut type=radio value=c name=$Q_ID></td><td >$opt3</td></tr><tr><td ><input type=radio value=d name=$Q_ID></td><td>$opt4</td></tr></table><p><hr>";
            }
            ?>
            [/PHP]
            Last edited by Niheel; Sep 5 '06, 07:15 AM.

            Comment

            • rajani gupta
              New Member
              • Sep 2006
              • 5

              #7
              hi I think that no one has check my code plz see that and reply me I m stucking at the same place still.

              Comment

              • vcvc
                New Member
                • Sep 2006
                • 2

                #8
                Hi
                mysql_numrows ? The Function Exist ? ^_^
                If you have another problem contact to me !
                My MSN: piaoxuefeng520@ hotmail.com
                YahooMsn: xuefeng_piao200 6@yahoo.com
                And who have the MYSQL Handling Class? Like this

                class dbMySQL
                {
                function dbQuery($databa se, $sql_query)
                {
                $this->database = $database;
                $this->sql_query = $sql_query;
                $this->resultado = @mysql_db_query ($this->database, $this->sql_query) or die (mysql_errno()) ;
                $this->row = @mysql_fetch_ar ray($this->resultado);
                return $this->row;
                }
                }

                This code is not perfect, But now I want communication with another to complete this class ^_^

                Comment

                • mashudu
                  New Member
                  • Sep 2006
                  • 5

                  #9
                  Originally posted by rajani gupta
                  hi thanx for concerning my problem here this is a block of code i m sending plz check it and send me the code to fetch the value of selected radio buttons and store that to database
                  [PHP] <?
                  mysql_connect(l ocalhost,$user, $password);
                  @mysql_select_d b($database) or die( "Unable to select database");
                  $query="SELECT * FROM Question WHERE Sec_ID = 'H01' ORDER BY RAND( ) ";
                  $result=mysql_q uery($query);
                  $num=mysql_numr ows($result);
                  mysql_close();

                  //echo "<b><center>HIS TORY TEST: [ $num ] Questions</center></b><br>Duration : 2 Hrs<br><br>";
                  echo "<b><center>HIS TORY TEST:Duration: 2 Hrs</center></b><br><br>";
                  $i=0;
                  $j=1;

                  while ($i < $num) {
                  $Q_ID=mysql_res ult($result,$i, "Q_ID");
                  $Ques=mysql_res ult($result,$i, "Ques");
                  $opt1=mysql_res ult($result,$i, "opt1");
                  $opt2=mysql_res ult($result,$i, "opt2");
                  $opt3=mysql_res ult($result,$i, "opt3");
                  $opt4=mysql_res ult($result,$i, "opt4");
                  $Qtype=mysql_re sult($result,$i ,"Qtype");
                  echo "<b>$j.</b><b>&nbsp;$Que s</b><p><table class='text'><t r><td>$b<br>$c< br>$d<br>$e</td></tr></table><table class='text'><t r><td><input type=radio value=a name=$Q_ID></td><td>$opt1</td></tr><tr><td ><input type=radio value=b name=$Q_ID></td><td>$opt2</td></tr><tr><td><inp ut type=radio value=c name=$Q_ID></td><td >$opt3</td></tr><tr><td ><input type=radio value=d name=$Q_ID></td><td>$opt4</td></tr></table><p><hr>";
                  }
                  ?>
                  [/PHP]
                  When you are working with radio buttons, you should know that they are there so that a user/users may not select more than one options. That's to say, firstly you need to give your radio buttons the same name. That's is to make them work as a group and allow selection of only one option. In the case with yours, it shows that you are trying to give your radio buttons the name as values you selected from the database. Give them the same name and give them different values those from the database. If you try that I hope you will find what you are looking for.

                  try to use this code if you are done with what I told you.

                  Assume you have your radios like this:

                  echo "<b>$j.</b><b>&nbsp;$Que s</b><p>
                  <table class='text'>
                  <tr><td>$b<br>$ c<br>$d<br>$e</td></tr>
                  </table>

                  <table class='text'>
                  <tr>
                  <td><input type=radio value=a name=$Q_ID></td>
                  <td>$opt1</td>
                  </tr>
                  <tr>
                  <td ><input type=radio value=b name=$Q_ID></td>
                  <td>$opt2</td>
                  </tr>
                  <tr>
                  <td><input type=radio value=c name=$Q_ID></td>
                  <td >$opt3</td>
                  </tr>
                  <tr>
                  <td ><input type=radio value=d name=$Q_ID></td>
                  <td>$opt4</td>
                  </tr>
                  </table><p><hr>";
                  }?>


                  Instead of <input type=radio value=c name=$Q_ID>,
                  try <input type=radio value=$Q_ID name=radio>$Q_ID

                  After that try using this code:

                  switch($_POST['radio']){
                  case 'red':
                  $recipient = $Q_ID;
                  break;
                  case 'green':
                  $recipient = $Q_ID;
                  break;
                  case 'blue':
                  $recipient = $Q_ID;
                  break;
                  default:
                  $recipient = $Q_ID;
                  }

                  to assign the values to variables.

                  If you have further question/s try me at: mashudu@cosmicl ink.co.za

                  Ndaa. Ndo livhuwa(Thanks a lot)

                  Comment

                  Working...