jeudi 29 octobre 2015

all form fields are working fine but image is not inserted into the table , its empty and does not show any error as

HERE IS MY CODE FOR INSERTION PRODUCT , EVERYTHING IS WORKING FINE WITH DB , BUT IMAGE COLUMN STAYS EMPTY WHENEVER I INSERT IMAGE /CHOOSE FILE . IT ALSO DOESNOT HAVE ANY EFFECT OR ERROR WHEN IMAGE IS NOT CHOOSEN , BUT IF I DO NOT CHOOSE OTHER FIELD , THE TABLE IN DB STAYS EMPTY . BUT ITS OPPOSIT IN CASE OF IMAGE . I I FOUND TUTOIAL ON IMAGE UPLOADING BUT THEY ARE NOT WORKING WD MY CODE AS WELL , any suggestions ?

<?php include 'includes/overall/head.php'; 
  include 'core/init.php';

         ?>
         <script src="//tinymce.cachefly.net/4.2/tinymce.min.js"></script>
         <script>tinymce.init({selector:'textarea'});</script>
         <?php
          include 'includes/aside.php';
    ?>
  <div class="container-form">
     <div  align="center"> 
        <h1>Insert Products</h1>
    </div>
        <!--Register users here-->
    <div class=> 
    <form action="insert_product.php" method="post"      enctype="multipart/form_data">
     <div class="table-responsive">
     <table class="table" width="700" align="center" border="1">

            <tr>
            <td><strong>Car Title</strong></td>
            <td><input type="text" name= "product_title"></td>
            </tr>
          <tr><td><strong>Car Category</strong></td>

            <td>
            <select  name="product_cat">
            <option >   Select Category</option>
            <?php
            // SQL query
            $strSQL = "SELECT * FROM categories  ";
             // Execute the query (the recordset $rs contains the result)
             $rs = mysql_query($strSQL);
             // Loop the recordset $rs
             while($row = mysql_fetch_array($rs)) {

             // Name of the person
             $cat_id = $row['cat_id'] ;
             $cat_title = $row['cat_title'] ;
             // Create a link to person.php with the id-value in the URL
          $strLink = "<a href = 'person.php?id = " . $row['cat_id'] . "'</a>";
             // List link
             echo "<option value='$cat_id'>$cat_title</option>";
             //echo "<li>" . $btitle . "</li>";

            }?>
          </select>
            </td>
            </tr>

            <tr>
                <td><strong>Car Company</strong></td>

                <td>
            <select  name="product_brand">
            <option >   Select Company</option>
               <?php
               // SQL query
                $brand = "SELECT * FROM brands  ";
                // Execute the query (the recordset $rs contains the result)
                $rs = mysql_query($brand);
                // Loop the recordset $rs
                while($row = mysql_fetch_array($rs)) {

                // Name of the person
                $brand_id = $row['brand_id'] ;
                $brand_title = $row['brand_title'] ;
                // Create a link to person.php with the id-value in the URL
                 $strLink = "<a href = 'person.php?id = " . $row['brand_id'] . "'</a>";
                // List link
                echo "<option value='$brand_id'>$brand_title</option>";
                //echo "<li>" . $btitle . "</li>";

                }?>
          </select>
            </td>    
             </tr>
             <tr>
            <td><strong>Add Image</strong></td>
              <td><input name="MAX_FILE_SIZE" value="102400" type="hidden">
              <input name="image" accept="image/jpeg" type="file"></td>
            </tr>


             <tr>
            <td><strong>Car Rent</strong></td>

            <td><input type="text" name= "product_price"></td>
            </tr>
             <tr>
            <td><strong>Car Description</strong></td>
            <td><textarea name="product_description"></textarea></td>
            </tr>
     <tr>
                <td><strong>Car Keyword</strong></td>
                <td><input type="text" name= "product_keywords"></td>
            </tr>


            <td colspan="2"> <button type="submit" name="insert_product" class="btn btn-primary col-md-offset-6">Add Vehicle</button>
     </td> 


           </table>
    </div>
    </form>
    <div>
    </div>
    </div>
    </div>
   <?php

     if(isset($_POST['insert_product'])){
        //text data variables
        $product_title=$_POST['product_title'];
        $product_cat=$_POST['product_cat'];
        $product_brand=$_POST['product_brand'];
        $product_price=$_POST['product_price'];
        $product_description=$_POST['product_description'];

        $product_status='on';
        $product_keywords=$_POST['product_keywords'];

        //image names: media file or multipart data 



        $product_img1=isset($_FILES['image']['name']);
        //Temp names
        $temp_name1=isset($_FILES['image']['temp_name']);
       //validation:


         if($product_title=='' OR $product_cat=='' OR $product_brand=='' OR $product_price==''OR $product_keywords=='' 
            OR $product_description=='' OR $image='') {
            echo "<script>alert('Please fill all the fields')</script>";
           exit();
         }

here is my upload image to folder code but its not working

      //upload images to folder
      move_uploaded_file($temp_name1 , "product_images/$product_img1");
        $query= "INSERT INTO product ( cat_id, brand_id, date, product_title,    image, product_price, product_description, product_status) 
        VALUES ( '$product_cat' , '$product_brand' , NOW() , '$product_title' , '$image' , '$product_price' , '$product_description' , '$product_status')";
        $rs = mysql_query($query);
       // Loop the recordset $rs
            if($rs) {
               echo 'Successful';
      }
      }
    ?>

    <!-------------------------------------------------------->
    <?php
    include 'includes/footer.php'; ?>




Aucun commentaire:

Enregistrer un commentaire