如何插入单选按钮的选中值,单选按钮是php中另一个表的数组

8cdiaqws  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(302)

我创建了一个测试表单,试图将来自gender表(包含:(1)male(2)female)的单选按钮值发送到另一个名为: ajebaje . 我现在有点问题。下面的代码只是一个测试,我想单选按钮提交值,但它不是。

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title> ajebaje </title>
    </head>
    <body>
        <form name="form1" action= "<?php echo $_SERVER["PHP_SELF"]; ?>"  method="post"> 
             <table width="20%" border="0" cellspacing="1" cellpadding="3">
                <tr>
                    <td><h4> Student's Gender </h4></td>
                    <td>
                        <?php
                            $con=mysqli_connect("localhost", "root", "ew6wLoLOro", "result");
                            $sql=mysqli_query($con, "select gender_sl_no, gender_name from gender")                
                            while($row=mysqli_fetch_array($sql))
                            {
                                 echo '<table>
                                           <input type="radio" name="sexbd" checked="checked"/>'.$row['gender_name'].'           
                                       </table>';
                            }
                        ?>
                   </td>
               </tr>  
               <tr>
                   <td> </td>
                   <td><input type ="submit" name="submit"/> </td>
               </tr>
           </table>
       </form>
       <?php
           $con=mysqli_connect("localhost", "root", "ew6wLoLOro", "result");
           $sexbd = $_POST['sexbd'];
           if(isset($_POST['submit']))
           {    
               echo $que="Insert into ajebaje VALUES(default,'$sexbd' )";
               echo " ";
               echo "Your Data Inserted";
               $result = mysqli_query($con,$que);
           }
       ?>
   </body>
</html>
zvokhttg

zvokhttg1#

默认情况下,它应该发送 sexbd: on 在表格中。
为了从表单发送值,需要在输入标记中定义value属性。像这样:

echo '<table>
          <input type="radio" name="sexbd" checked="checked" value='.$row['gender_name'].'/>'.$row['gender_name'].'
      </table>';

呈现的形式如下所示:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title> ajebaje </title>
    </head>
    <body>
        <form name="form1" action= "/test"  method="post"> 
             <table width="20%" border="0" cellspacing="1" cellpadding="3">
                <tr>
                    <td><h4> Student's Gender </h4></td>
                    <td>
                        <table>
                            <input type="radio" name="sexbd" checked="checked" value="Male"/> Male          
                        </table>
                        <table>
                            <input type="radio" name="sexbd" checked="checked" value="Female"/> Female          
                       </table>
                   </td>
               </tr>  
               <tr>
                   <td> </td>
                   <td><input type ="submit" name="submit"/> </td>
               </tr>
           </table>
       </form>
   </body>
</html>

现在,提交的值将是 sexbd: Male 或者 sexbd: Female

相关问题