HIADARSAB NADAF

HIADARSAB NADAF

  • NA
  • 14
  • 7.7k

Upload image into sql server using php

Jun 13 2015 1:03 AM
Hi, everyone
I am trying to upload image name into database and the image to specified file directory and also textbox values are insert into database so, below is my code please tell me what is wrong with this code.
 
Thank in advance.
 
      <?php
      $target_Path = "images/";  //storing image path.
      $filename = 'user_file';
      $target_Path .= $filename["user_file"];
      $ToiletId = "anythning";
      $target_Path = $target_Path.basename( $_FILES['user_file']['name'] );
      move_uploaded_file( $_FILES['user_file']['tmp_name'], $target_Path );

      include('dbconfig.php');
      include ('userid.php');
      if (isset($_POST['Toilet_Id'], $_POST['submit'])) {

      $toiletid = $_POST['Toilet_Id'];
      $cleanedrooms = $_POST['cleanedrooms'];
      $description = $_POST['description'];
      $user_file = $_POST['user_file'];
      $submit = $_POST['submit'];

      $sql = "SELECT * FROM Toilet where [ToiletID] = '$toiletid' ";
      $result = sqlsrv_query($conn, $sql);

      while($row = sqlsrv_fetch_array($result)){

      $toiletid = $row['ToiletID'];
      $toiletname = $row['ToiletName'];
      $totalrooms = $row['ToiletRooms'];
      }

      if(empty($_POST['cleanedrooms']) && empty($_POST['description'])
      && empty($_POST['userfile']))
      {
      echo "<script> alert('You have to fill in everything in the form.')</script>";
      }
      else {

      $query = "INSERT INTO [Toilet_Clean_Status] (
      [ToiletID],
      [cleanRooms],
      [description],
      [Updatedby],
      [UpdatedDate],
      [image])

      VALUES ('$toiletid',
      '$cleanedrooms',
      '$description',
      '$user',
      getdate(),
      '$ImageName')";
      }
      }
      ?>

      <!DOCTYPE html>
      <html>
      <head>
      <title>Toilet Clean Status</title>
      </head>
      <body>
      <h1 style="color:gray; font-size:30px;">Toilet Clean Status</h1>

      <div id="form1">
      <form name="form2" id="form2" method="POST" action="" enctype="multipart/form-data">
      <table border="4" width:100%; cellpadding="10" cellspacing="1">
      <tr><td><label style="font-size:20px;">Toilet ID</label></td><td><input type="text" readonly="" value="<?php echo $toiletid; ?>" /> </td></tr>
      <tr><td><label style="font-size:20px;">Toilet Name</label></td><td>  
      <input type="text" readonly="" value="<?php echo $toiletname; ?>" /></td></tr>
      <tr><td><label style="font-size:20px;">Toilet Rooms</label></td><td>
      <input type="text" readonly="" value="<?php echo $totalrooms; ?>"/> </td></tr>
      <tr><td><label style="font-size:20px;">Cleaned Rooms</label></td><td><input type="text" name="cleanedrooms" ></td></tr>
      <tr><td><label style="font-size:20px;">Description</label></td><td><input type="text" name="description" ></td></tr>
      <tr><td><label style="font-size:20px;">Upload New Image</label></td><td><input type="file" name="user_file" ></td></tr>

      </table>
      <div>
      <input type="submit" name="submit" value="Save" style=" position: absolute; top: 500px; left: 190px;
      color:white;background-color:gray; height:30px">
      </div>
      </form>
      </div>
      </body>
      </html>

Answers (1)