1

I'm rookie at php and html, i have this modal that has in it which i need for inserting an 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">&times;</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 this is the php file which the modal will 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' WHERE RoomTypeID = 
".$roomtypeid);
                echo "<script>";
        echo "alert(\"Successfully Added!\");";
        echo "</script>";
            }else{
                echo "<script>";
        echo "alert(\"File size too big!\");";
        echo "</script>";
            }
        }else
        {
        echo "<script>";
        echo "alert(\"There was an error\");";
        echo "</script>";
        }

    }else
    {
        echo "<script>";
        echo "alert(\"You cannot upload this type of file\");";
        echo "</script>";

    }
    }
?>

but this error keep on occurring : Notice: Undefined index: add_roomtypeImgnm... help me out here guys, i don't know whats the problem. I already tried to change the name and id of my and same error keeps on occurring.

jay r bayog
  • 53
  • 2
  • 8

1 Answers1

0

The reason why you cannot post files is not your modal dialog but the fact that you are not using enctype="multipart/form-data" in your form.

Try it like this and it should work.

steven
  • 4,868
  • 2
  • 28
  • 58