daily pastebin goal
54%
SHARE
TWEET

Untitled

a guest Jan 16th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $duom=$_POST['duom'];
  3. if(isset($_POST['submit'])) {
  4.     if ($_FILES[data][size] > 0) {
  5.         $file = $_FILES[data][tmp_name];
  6.         ini_set('auto_detect_line_endings',TRUE);
  7.         $read = fopen($file, "r");
  8.         try {
  9.  
  10.             $stmt =$pdo->prepare ("INSERT INTO prekes(id,katid,pavadinimas,aprasymas,kiekis,kaina,photo,sandid) VALUES (:id, :katid, :name, :description, :quantity, :price, :photo, :sandid)");
  11.             $stmt->bindParam(':id', $id);
  12.             $stmt->bindParam(':katid', $katid);
  13.             $stmt->bindParam(':name', $name);
  14.             $stmt->bindParam(':description', $description);
  15.             $stmt->bindParam(':quantity', $quantity);
  16.             $stmt->bindParam(':price', $price);
  17.             $stmt->bindParam(':photo', $photo);
  18.             $stmt->bindParam(':sandid', $sandid);
  19.             while (($data = fgetcsv($read, 10000, ";")) !== FALSE) {
  20.                 $id = $data[0];
  21.                 $katid = $data[1];
  22.                 $name = $data[2];
  23.                 $description = $data[3];
  24.                 $quantity = $data[4];
  25.                 $price = $data[5];
  26.                 $photo = $data[6];
  27.                 $sandid = $data[7];
  28.                 $stmt->execute();
  29.  
  30.             }
  31.  
  32.         } catch (Exception $e) {
  33.             echo "Negaliu pridėti naujo įrašo";
  34.             $messages['error'] = $e->getMessage();
  35.             exit;
  36.             echo $e->getMessage();
  37.  
  38.  
  39.         }
  40.     }
  41. }
  42.  
  43. ?>
  44. <form method="post" enctype="multipart/form-data">
  45.     <div class="form-group">
  46.         <label class="control-label col-md-3 col-sm-3 col-xs-12" for="duom">produktas <span class="required">*</span>
  47.         </label>
  48.         <div class="col-md-6 col-sm-6 col-xs-12">
  49.             <input type="file" id="duom" name="data" required="required" class="form-control col-md-7 col-xs-12">
  50.         </div>
  51.     </div>
  52.     <div class="form-group">
  53.         <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
  54.             <button type="submit" name="submit" class="btn btn-success">Išsaugoti</button>
  55.         </div>
  56.     </div>
  57.     <script>
  58.         // Replace the <textarea id="editor1"> with a CKEditor
  59.         // instance, using default configuration.
  60.         CKEDITOR.replace( 'descr' );
  61.     </script>
  62. </form>
RAW Paste Data
Top