duanpacan2583
duanpacan2583
2015-05-29 05:56

单选按钮值未存储在数据库中

I created a radio button in which when user click on yes value then text box is shown to user otherwise they remain hide.
My question when user select yes then I am able to store yes value in sql but when user click on no value that value is not stored in datbase

<script>
$(document).ready(function(){
  $(function() {
     $('input[name="yeshave"]').on('click', function() {
        if ($(this).val() == 'yes') {
           $('#textboxes').show();
        } else {
           $('#textboxes').hide();
        }
     });
   });
});
</script>

no radio button code:

<table>
   <tr>
      <td>Do you haver passport:</td>
      <td><input type="radio" name="yeshave" value="yes"> Yes</td>
      <td><input type="radio" name="yeshave" value="no"> No</td>
   </tr>
</table>

SQL code is:

if(isset($_POST['yeshave']))
{
    $selectedValue=$_POST['yeshave'];
}



 $query = "INSERT INTO upload (name, size, type, image,passport_no,dateofissue,dateofexpiry,placeofissue, having_passport ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$image','".$passno."','".$doi."','".$doe."','".$poi."','".$selectedValue."')";

mysqli_query($conn,$query) or die('Error, query failed');
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • douxunwei8259 douxunwei8259 6年前

    Set check one of them. Try with -

    $selectedValue = isset($_POST['yeshave']) ? $_POST['yeshave'] : 'no';
    
    点赞 评论 复制链接分享
  • duanru6816 duanru6816 6年前

    JavaScript:

    $(document).ready(function() {
        $('input[name="yeshave"]').on('click', function() {
            $('#textboxes').toggle($(this).val() == 'yes');
        });
    });
    

    In PHP:

    $selectedValue = $_POST['yeshave'] ? $_POST['yeshave'] : 'no';
    
    1. You don't need $(function() inside ready
    2. Use toggle to hide/show #textboxes
    3. In PHP, check if value is present, if not use default no
    点赞 评论 复制链接分享

为你推荐