How to call an option in php?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Louloul
    New Member
    • Aug 2010
    • 7

    How to call an option in php?

    I want to call from a form the radio option and put it in sql(php)
    -this is the html code
    Code:
    <input type="radio" name="rb" ID="Radio1" VALUE="Radio1" <select id="Select1" name="Kinder"> 
    <option value="1">Nursery</option> 
    <option value="2">Kg1</option> 
    <option value="3">Kg2</option> 
    </select> 
    <td>
    </tr>
    <tr>
    <td align=center>
    <select name="elem" id="Select2"> 
    <option value="1">Grade1</option> 
    <option value="2">Grade2</option> 
    <option value="3">Grade3</option> 
    <option value="4">Grade4</option> 
    <option value="5">Grade5</option> 
    <option value="6">Grade6</option> 
    <option value="7">Grade7</option> 
    <option value="8">Grade8</option> 
    <option value="9">Grade9</option> 
    </select>
    -this is the php code
    Code:
    if(isset($_POST["C"]))
    $t="document.form.getElementsByTagName('option').value";
    $C=$_POST['t'];
    
    include('MySQLConnection.php');
    $result=mysql_query("INSRET INTO registration (ID_etu, level_etu, class_etu, section_etu, date_reg ) 
    values('', '".$rb."', '".$C."', '".$rd1."', '".$dt."'");
    $sql=mysql_query($result. "mysql_error()");
    ?>
    it is giving me an error:

    Notice: Undefined index: t in C:\wamp\www\www \Register.php on line 15

    Can anyone help? How should I write it?

    Thanks for any help
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    You never closed your input tag in your html.
    Code:
    <input type="radio" name="rb" ID="Radio1" VALUE="Radio1" /> 
    <select id="Select1" name="Kinder"> 
    <option value="1">Nursery</option> 
    <option value="2">Kg1</option> 
    <option value="3">Kg2</option> 
    </select> 
    <td>
    </tr>
    <tr>
    <td align=center>
    <select name="elem" id="Select2"> 
    <option value="1">Grade1</option> 
    <option value="2">Grade2</option> 
    <option value="3">Grade3</option> 
    <option value="4">Grade4</option> 
    <option value="5">Grade5</option> 
    <option value="6">Grade6</option> 
    <option value="7">Grade7</option> 
    <option value="8">Grade8</option> 
    <option value="9">Grade9</option> 
    </select>
    Form values are passed to the $_POST[] variable.
    You access those values by their name.
    For your radio button it would be $_POST['rb']

    Any user input should be escaped using mysql_real_esca pe_string() before inserting it into a query to prevent sql injection attacks.

    Your error that you are receiving means there is no input with the name of "t".

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      JKing: You access those values by their ID.

      Your error that you are receiving means there is no input with the id of "t".
      Don't you mean by their "name"?
      It's the "name" attribute of the <input> tag that is used as the element name in the $_POST or $_GET arrays, not the "id" attribute.

      Comment

      • JKing
        Recognized Expert Top Contributor
        • Jun 2007
        • 1206

        #4
        Yes that is what I mean. Thank you for spotting the mistake.

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          You never closed your input tag in your html.
          input elements must not be closed in HTML.

          Comment

          • JKing
            Recognized Expert Top Contributor
            • Jun 2007
            • 1206

            #6
            It would still require the closing angle bracket.

            Comment

            • kovik
              Recognized Expert Top Contributor
              • Jun 2007
              • 1044

              #7
              Self-closing tags are still closed. :P

              Comment

              • Atli
                Recognized Expert Expert
                • Nov 2006
                • 5062

                #8
                He means, the OP fails to close the elements themselves.
                [code=html]
                <input type="whatever" <select ...>

                <-- Should be -->

                <input type="whatever" ><select ...>
                [/code]

                Comment

                Working...