title: Any suggestion or solution to my problem to inject selected list items from dropdownlist to other table in php, mysql
body: <p>Working on a small image gallery project in php and mysql. The project has two table. Album (albumId and albumName) and gallery(id, imageName, albumId, img_name). So, when user need to create a image gallery, they need to input all the information like title, album name, and image. I am able to do most of the part, the section I was stuck was with inserting the dropdown list, which in my case is album. Here is my add_photo.php</p>
  
  <pre><code>&lt;!--Adding Post Area--&gt;    
      &lt;form action="add_photo_check.php" method="POST" enctype="multipart/form-data"&gt;
         &lt;?php
            if(isset($_SESSION['message']))
            {
                echo $_SESSION['message'];
                unset($_SESSION['message']);
            }
            ?&gt;
         &lt;!--Form for post--&gt;
         &lt;div class="form-group"&gt;
            &lt;label for="posttitle"&gt;
               &lt;h5&gt;Photo Title&lt;/h5&gt;
            &lt;/label&gt;
            &lt;textarea name="imageName" class="form-control" placeholder="photo title.." &gt;&lt;/textarea&gt;
         &lt;/div&gt;
         &lt;div class="form-group"&gt;
             &lt;label for="album"&gt;Select Album&lt;/label&gt;
             &lt;select class="form-control" name="albumId" id="album"&gt;
                 &lt;option&gt;Select Album&lt;/option&gt;
            &lt;?php
               $sql = "select * from album";
                $res = mysqli_query($conn,$sql);      
                while($row=mysqli_fetch_assoc($res)){
                    echo"&lt;option value=\"" .$row['albumId'] . "\" &gt;" .$row['albumName']."&lt;/option&gt;\n";
                }
  
               ?&gt;
                &lt;/select&gt;
                &lt;/div&gt;
            &lt;div class="form-group"&gt;
               &lt;label for="uploadimage"&gt;
                  &lt;h5&gt;Upload image&lt;/h5&gt;
               &lt;/label&gt;
               &lt;div class="btn"&gt;
                  &lt;input type="file" name="image"&gt;
               &lt;/div&gt;
            &lt;/div&gt;
            &lt;input type="submit" value="Publish" name="publish" class="btn btn-primary"&gt;
      &lt;/form&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>This is my function file add_photo_check.php</p>
  
  <pre><code>&lt;?php
  include "includes/header.php";
  if(isset($_POST['publish']))
  
  {
    $title=$_POST['imageName'];
    $title=mysqli_real_escape_string($conn,$imageName);
    $title=htmlentities($imageName);
  
    $id=$_POST['albumId'];
    $id=mysqli_real_escape_string($conn,$albumId);
    $id=htmlentities($albumId);
  
  
    $uploadOk = 1;
      $img_name = $_FILES['image']['name'];
      $errorMessage = "";
  
      if($img_name != "") {
          $targetDir = "images/upload/";
          $img_name = $targetDir . uniqid() . basename($img_name);
          $imageFileType = pathinfo($img_name, PATHINFO_EXTENSION);
  
  
  
      if(strtolower($imageFileType) != "jpeg" &amp;&amp; strtolower($imageFileType) != "png" &amp;&amp; strtolower($imageFileType) != "jpg") {
        $_SESSION['message']="&lt;div class='alert alert-danger'&gt;  Sorry, only jpeg, jpg and png files are allowed!&lt;/div&gt;";
              $uploadOk = 0;
      }
  
      if($_FILES['image']['size'] &gt; 100000){
        $_SESSION['message']="&lt;div class='alert alert-danger'&gt; Image is too big to upload!&lt;/div&gt;";
        header("Location: add_photo.php");
  
        }
  
      if($uploadOk) {
              if(move_uploaded_file($_FILES['image']['tmp_name'], $img_name)) {
                  //image uploaded okay
              }
  
        $sql="insert into gallery (title, id, img_name) value('$imageName','$albumId', '$img_name')";
        $res=mysqli_query($conn,$sql);
        if($res)
        {
        $_SESSION['message']="&lt;div class='alert alert-success'&gt; Post Successfuly Published&lt;/div&gt;";
        header("Location: add_photo.php");
        }
        else
        {
          $_SESSION['message']="&lt;div class='alert alert-danger'&gt; Something went wrong!&lt;/div&gt;";
          header("Location: add_photo.php");
        }
      }
    } 
  
  }
  
  ?&gt; 
  </code></pre>
  
  <p>Any help will be greatly appreciated. Thank you.</p>