【问题标题】:Insert radio button value in database在数据库中插入单选按钮值
【发布时间】:2015-08-12 02:27:17
【问题描述】:

我正在做一个项目。哪里有你有护照的单选按钮。如果用户选择是,则向用户显示更多文本框和上传护照图像的按钮,否则它们将隐藏。 我的问题是,当用户选择“是”并填写完整的详细信息时,它可以正常工作,当用户选择“否”按钮或其他情况时,当用户选择“是”但未选择要上传的图像时,他/她在文本框中填写的其余数据不会“ t 进入数据库。我将非常感谢这可以消除我的错误。 我使用 BLOB 类型将图像直接存储在数据库中。 这是我的代码:

<?php
 $conn = new mysqli("localhost","root","","db_dat");

 $passno="";
 $doi="";
 $doe="";
 $poi="";
 if (isset($_POST['pass']))
 {
  $passno=$_POST['pass'];
 }
 if (isset($_POST['dateofissue']))
 {
  $doi=$_POST['dateofissue'];
 }
 if (isset($_POST['dateofexpiry']))
 {
  $doe=$_POST['dateofexpiry'];
 }
 if (isset($_POST['issueplace']))
 {
  $poi=$_POST['issueplace'];
 }
 if(isset($_POST['yeshave']))
 {
  $selectedValue =$_POST['yeshave'];
 }
 ?> 

<?php
 //image script
 if(isset($_POST['submit']) && $_FILES['userfile']['size'] > 0)
 {
  $fileName = $_FILES['userfile']['name'];
  $tmpName = $_FILES['userfile']['tmp_name'];
  $fileSize = $_FILES['userfile']['size'];
  $fileType = $_FILES['userfile']['type'];

  $fp = fopen($tmpName, 'r');
  $image = fread($fp, filesize($tmpName));
  $image = addslashes($image);
  fclose($fp);

  if(!get_magic_quotes_gpc())
  {
   $fileName = addslashes($fileName);
  }
  //imagescriptend
  $servername = "localhost";
  $username = "root";
  $password = "";
  $dbname = "db_dat";

  $conn=mysqli_connect($servername, $username, $password, $dbname);

  $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'); 

  echo "<br>File $fileName uploaded<br>";
 } //ifissetpost submit end
?>

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <!-- Set the viewport width to device width for mobile -->
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
  <script>
   $(document).ready(function(){
   $(document).ready(function() {
    $('input[name="yeshave"]').on('click', function() {
     $('#textboxes').toggle($(this).val() == 'yes');
    });
   });
   });
  </script>
  <link rel="stylesheet" 
   href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="http://jqueryui1.com/resources/demos/style.css">
  <script>
   $(function() {
    $( "#datepickerfordoi" ).datepicker();
   });
  </script>
  <script>
   $(function() {
    $( "#datepickerfordoe" ).datepicker();
   });
  </script>
 </head>
 <body>
  <form method="post" enctype="multipart/form-data">
  <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>
  <divine id="textboxes" style="display: none">
   <table>
    <tr>
     <td>Passport No:</td>
     <td>
      <input type="text" name="pass">
     </td>
    </tr>
    <tr>
     <td>Date of Issue:</td>
     <td>
      <input type="text" name="dateofissue" id="datepickerfordoi"> 
     </td>
    </tr>
    <tr>
     <td>Date of expiry:</td>
     <td> <input type="text" name="dateofexpiry" id="datepickerfordoe"> </td>
    </tr>
    <tr>
     <td width="246"><br><br>
      <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
      <input name="userfile" type="file" id="userfile"> 
     </td>
    </tr>
   </table>
  </divine>
  <table>
   <tr>
    <td>
    <td>
     <input name="submit" type="submit" class="fsSubmitButton" 
      id="upload" value=" submit ">
    </td>
   </tr>
  </table>
 </body>
</html>

【问题讨论】:

  • 请检查您的代码是否存在 SQL 注入。您不想被黑客入侵。
  • 请避免使用水平滚动条。它使帖子的阅读变得更加困难。
  • 先生,实际上我的提交按钮适用于提交按钮 name="upload" 中的图片上传,因此当用户不选择图片时,不会发布任何数据
  • 所以你明白了吗?回答了你自己的问题?

标签: javascript php jquery mysql radio-button


【解决方案1】:

因为我的图片和其他打开的文本框正在处理一个名为 upload 的提交按钮,并且在我的图片脚本中我设置了 upload 。因此,如果用户不选择图像,它将无法正常工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-10
    • 1970-01-01
    • 2018-09-18
    • 2022-01-22
    • 1970-01-01
    • 2014-11-04
    • 1970-01-01
    相关资源
    最近更新 更多