javascript - How to insert multiple images in different column same row using php (assign separate column field) -


database:
actual field in database

`users` (   `itemid` int(11) not null,   `itemname` varchar(20) not null,   `isfragile` varchar(255) not null,   `noofpiece` int(20) not null,   `userprofile` varchar(200) not null,   `userprofile2` varchar(255) not null,   `userprofile3` varchar(225) not null,   `userprofile4` varchar(255) not null,   `userprofile5` varchar(255) not null,   `rrid` int(11) not null,   `tempguid` int(11) not null,   `createdon` datetime not null,   `updatedon` datetime not null 

html form:

using javascript add multiple images , calling in php name="file[]" function.

<form method="post" enctype="multipart/form-data" class="form-horizontal" style="margin: 0 300px 0 300px;border: solid 1px;border-radius:4px">     <table class="table table-responsive">     <h2 style="text-align: center;font-size: 24px;color: #5db85c;font-weight: 600;">add item </h2>     <tr>         <td><label class="control-label">item name</label></td>         <td><input class="form-control" type="text" name="itemname" placeholder="enter item name" value="<?php echo $itemname; ?>" /></td>     </tr>     <tr>         <td><label class="control-label">pieces</label></td>         <td><input class="form-control" type="number" name="noofpiece" placeholder="number of pieces" value="<?php echo $noofpiece; ?>" /></td>     </tr>     <tr>         <td><label class="control-label">pictures</label></td>         <td><div id="filediv"><input name="file[]" type="file" id="file"/></div> <input type="button" id="add_more" class="upload" value="add more files" style="font-size: 11px; margin-top: 8px;height: 34px;"/></td>      </tr>        <tr>         <td><label class="control-label">fragile</label></td>         <td><label class="heading"></label> <input type="checkbox" name="isfragile[]" value="yes"><label> &nbsp;yes</label> &nbsp;&nbsp;&nbsp; <input type="checkbox" name="isfragile[]" value="no"><label> &nbsp;no</label></td><br/> <?php include "upload.php"; ?>     </tr>     <tr>         <td colspan="2" align="center"><button type="submit" name="btnsave" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-save"></span>&nbsp; save</button>         </td>     </tr>     </table> </form> 

php code:

here want create loop, array or etc assign database field(column) each image.

<?php     error_reporting( ~e_notice );     require_once 'dbcon.php';     if(isset($_get['delete_id']))     {         $stmt_select = $db_con->prepare('select userprofile users itemid =:uid');         $stmt_select->execute(array(':uid'=>$_get['delete_id']));         $imgrow=$stmt_select->fetch(pdo::fetch_assoc);         unlink("user_images/".$imgrow['userprofile']);         $stmt_delete = $db_con->prepare('delete users itemid =:uid');         $stmt_delete->bindparam(':uid',$_get['delete_id']);         $stmt_delete->execute();             header("location: addmember.php");     }      if(isset($_post['btnsave']))      {         /*  name   */         $itemname = $_post['itemname'];          /* fragile  */         if(isset($_post['isfragile'])) foreach($_post['isfragile'] $chk1)  {  $chk= $chk1;  }           /*  quanity */         $noofpiece = $_post['noofpiece'];           /*  quanity */          $imgfile = $_files['file']['name'];         $tmp_dir = $_files['file']['tmp_name'];         $imgsize = $_files['file']['size'];          if(empty($itemname)){             $errmsg = "please enter itemname.";         }         else if(empty($chk)){             $errmsg = "please select 1 option.";         }         else if(empty($noofpiece)){             $errmsg = "please enter number of pieces.";         }         else if(empty($imgfile)){             $errmsg = "please select image file.";         }         else         {             $upload_dir = 'uploads/';             $imgext = strtolower(pathinfo($imgfile,pathinfo_extension));             $valid_extensions = array('jpeg', 'jpg', 'png', 'gif');             $userprofile = rand(1000,1000000).".".$imgext;             if(in_array($imgext, $valid_extensions)){                 if($imgsize < 5000000)              {                     move_uploaded_file($tmp_dir,$upload_dir.$userprofile);                 }                 else{                     $errmsg = "sorry, file large upload. should less 5mb.";                 }             }             else{                 $errmsg = "sorry, jpg, jpeg, png & gif extension files allowed.";                   }         }          if(!isset($errmsg))         {             $stmt = $db_con->prepare('insert users(itemname,isfragile,noofpiece,userprofile,createdon) values(:uname,:ufa, :udes, :upic, now())');             $stmt->bindparam(':uname',$itemname);             $stmt->bindparam(':ufa',$chk);             $stmt->bindparam(':udes',$noofpiece);             $stmt->bindparam(':upic',$userprofile);             if($stmt->execute())             {                 $successmsg = "successfully added new item.";                 header("refresh:1;addmember.php");             }             else             {                 $errmsg = "error while creating.";             }         }     } ?> 

i new php world, need easy solution. hope hear positive , suitable feedback.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -