html - why <input = "file"> on modal can't pass image to php -
i'm rookie @ php , html, have modal has in need inserting image..
if (isset($_post['add_roomtype_action'])) { require 'script/addroomtype.php'; } <div class="modal fade" id="add_roomtype_modal" tabindex="-1" role="dialog" aria-labelledby="add_roomtype_modal" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria- hidden="true">×</button> <h4 class="modal-title" id="mymodallabel">add room type</h4> </div> <form action="room_management.php" method="post" autocomplete="off"> <div class="modal-body"> <input type="hidden" id="upd_roomtype_id" name = "add_roomtype_idnm"> <label style="font-size: 10pt">room type : </label> <input type="text" id="add_roomtype" name = "add_roomtypenm" style="font-size: 10pt" ><br></br> <label style="font-size: 10pt">rate : </label> <input type="text" id="addupd_rate" name = "add_ratenm" style="font-size: 10pt" ><br></br> <label style="font-size: 10pt">image : </label> <input type="file" id ="add_roomtypeimgid" name="add_roomtypeimgnm" accept="image/x-png,image/jpeg"> </div> <div class="modal-footer"> <button type="button" class="btn" data- dismiss="modal">close</button> <button type="submit" class="btn" id = "add_roomtype_action" name = "add_roomtype_action">add</button> </div> </form> </div> </div> </div> and php file modal call
<?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "afgroms"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } if(isset($_post['add_roomtype_action'])){ $roomtypeid = $_post['add_roomtype_idnm']; $roomtype = $_post['add_roomtypenm']; $rate = $_post['add_ratenm']; $file = $_files['add_roomtypeimgnm']; $filename = $file['name']; $filetmpname = $file['tmp_name']; $filesize = $file['size']; $fileerror = $file['error']; $filetype = $file['type']; $fileext = explode('.', $filename); $fileactualext = strtolower(end($fileext)); $allowed = array('jpg','jpeg','png'); if(in_array($fileactualext, $allowed)){ if($fileerror === 0) { if ($filesize > 500000) { mysql_query("update `tbl_roomtype` set `roomtype` = '$roomtype', `rate` = '$rate', `image` = '$img' roomtypeid = ".$roomtypeid); echo "<script>"; echo "alert(\"successfully added!\");"; echo "</script>"; }else{ echo "<script>"; echo "alert(\"file size big!\");"; echo "</script>"; } }else { echo "<script>"; echo "alert(\"there error\");"; echo "</script>"; } }else { echo "<script>"; echo "alert(\"you cannot upload type of file\");"; echo "</script>"; } } ?> but error keep on occurring : notice: undefined index: add_roomtypeimgnm... me out here guys, don't know whats problem. tried change name , id of , same error keeps on occurring.
the reason why cannot post files not modal dialog fact not using enctype="multipart/form-data" in form.
try , should work.
Comments
Post a Comment