2015-05-29 34 views
1

我正在開發一個項目。哪裏有一個單選按鈕你有護照嗎?如果用戶選擇是,則會向用戶顯示進一步的文本框和用於上傳護照圖像的按鈕,以供他們隱藏。 我的問題是,當用戶選擇是並填寫完整的詳細信息,然後它工作正常,當用戶選擇沒有按鈕或其他情況下,當用戶選擇是,但沒有選擇圖像上傳然後休息數據他/她填寫文本框doesn不要進入數據庫。我將非常感謝這個刪除我的錯誤。 我使用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> 
+0

請檢查您的代碼SQL注入。你不想被黑客入侵。 –

+0

請避免使用水平滾動條。它使閱讀帖子更難。 – reporter

+0

實際上,我的提交按鈕在提交按鈕名稱=「上傳」時適用於圖像上傳,所以當用戶沒有選擇圖像時沒有發佈數據 –

回答

0

Cauz我的形象和休息是開放的是在一個工作提交按鈕,其名稱是上傳和我的形象腳本我設置上傳其他文本框。所以,如果用戶沒有選擇一個圖像,它不能正常工作

相關問題