php - failed prepared statement and img file upload -


i attempting create first prepared statement , use see i'm doing wrong. had of query working before doing this, told me should way prevent sql injection.

i'm trying send product info database. included in data, trying send img file , have moved db. before attempting prepared statement doing simple mysqli insert statement , part of query did not work getting file name of img show in database actual file name. way uploading "array" or "1". changed things around try make work procedure statement best could.

i'm not sure if attempt upload img file correct in prepared statement or not. reason being none of being sent data base now. not getting errors database connection.

i start off validation. not have validation img file yet. add later once can send.

i process form info. i'm not sure if $file variable structured right sending file name db i'm getting error.

i error php error info on.. notice: undefined index: img in /home4/pfarley1/public_html/addproduct.php on line 90

//create $date = date('y-m-d h:i:s');  if($validation->passed()) {     if(isset($_post['create'])){          $product_id = trim( $_post['product_id'] );         $name = trim( $_post['name'] );         $price = trim( $_post['price'] );         $saleprice = trim( $_post['saleprice'] );         $final_price = trim( $_post['final_price'] );         $shippingprice = trim( $_post['shippingprice'] );         $category = trim( $_post['category'] );         $item_details = trim( $_post['item_details'] );         $item_details2 = trim( $_post['item_details2'] );         $description = trim( $_post['description'] );         $viewproduct_type = trim( $_post['viewproduct_type'] );         $date = ( $_post['date_created'] );  //line 90 $file = ($_post ['img'] [move_uploaded_file($_files['file']['tmp_name'],"productpics/". $_files['file']['name'])] );      //connection     $con = mysqli_connect("localhost","root","","bfb");     /* check connection */         if (mysqli_connect_errno()) {             printf("connect failed: %s\n", mysqli_connect_error());             exit();         }        /* create prepared statement */     if ($stmt = mysqli_prepare($con, "insert products ('product_id', 'name', 'price', 'saleprice', 'final_price', 'shippingprice', 'category', item_details', 'item_details2', 'description', 'viewproduct_type', 'date', 'img') values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {           /* bind parameters markers */         $stmt->bind_param('isiiiisssssis', $product_id, $name, $price, $saleprice, $final_price, $shippingprice, $category, $item_details, $item_details2, $description, $viewproduct_type, $date, $file);          /* execute query */         $stmt->execute();       /* close statement */     mysqli_stmt_close($stmt);         }     }   }  }  }    ?> 

the form

<form action="" method="post" enctype="multipart/form-data">     <div class="field">         <label for="product_id">product id</label>         <input type="text" name="product_id" class="smallinputbar" required>     </div>     <div class="field">         <label for="name">product name</label>         <input type="text" class="inputbar" name="name" required>     </div>     <div class="field">         <label for="price">product price</label>         <input type="text" class="smallinputbar" name="price" required>     </div>     <div class="field">         <label for="saleprice">sale price</label>         <input type="text" class="smallinputbar" name="saleprice">     </div>     <div class="field">         <label for="final_price">final price</label>         <input type="text" class="smallinputbar" name="final_price" required>     </div>     <div class="field">         <label for="shippingprice">shipping price</label>         <input type="text" class="smallinputbar" name="shippingprice" required>     </div>     <div class="field">         <label for="category">category</label>         <input type="text" class="inputbar" name="category" required>     </div>     <div class="field">         <label for="item_details">item details</label>         <input type="message" class="messageinput" name="item_details" required>     </div>     <div class="field">         <label for="item_details2">item details 2</label>         <input type="message" class="messageinput" name="item_details2">     </div>     <div class="field">         <label for="description">description</label>         <input type="message" class="messageinput" name="description" required>     </div>     <div class="field">         <label for="viewproduct_type">view product type</label>         <select class="optionbar" name="viewproduct_type">             <option name="notselected">not selected</option>             <option name="viewproduct_type" value="a href='./viewproduct.php?view_product=$id">standard</option>             <option name="viewproduct_type" value="option">option</option>         </select>     </div>          <input type="hidden" name="token" value="<?php echo token::generate(); ?>">         <label for="button">          <input type="submit" id="button" name="create" value="create new product">         </label>      <span class="floatright">         <input type="file" name="file" class="inputbarfile">         <input type="submit" name="create" id="signinbutton" value="upload">     </span> 

i followed examples php manual , youtube, none doing, adding in img file upload.

does see doing wrong prepared statement or way trying upload img file? i've been stuck in img file upload long time , have tried million different ways.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -