<?php require_once("../includes/session.php");?>
<?php require_once("../includes/connection.php");?>
<?php require_once("../includes/function.php");?>
<?php confirm_logged_in();?>
<?php require_once("../includes/validation_functions.php");?>

<?php
if(isset($_POST['submit'])){

    //process the form
    // often there are form values in $_POST



        $product_name = mysql_prep($_POST["product_name"]);
        $product_amount = (int) $_POST["product_amount"];
        $visible = (int) $_POST["visible"];
    foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
        $file_tmp =$_FILES['files']['tmp_name'][$key];
        $uploaded_dir = "images/"; 
        $filename = $_FILES['files']['name'][$key];
        $path = $uploaded_dir . $filename; 
        move_uploaded_file($file_tmp,"images/".$_FILES['files']['name'][$key]);

        $query  ="INSERT INTO products (";
        $query .=" name, amount, visible";
        $query .=") VALUES (";
        $query .=" '{$product_name}',{$product_amount},{$visible}";
        $query .=")";
        $result = mysqli_query($connection,$query);
        $last_id = mysqli_insert_id($connection);
        $sql.= "('$last_id','$path'),";
        $sql ="INSERT INTO images ( productID, file_name ) VALUES". trim($sql,',');
        $results = mysqli_query($connection,$sql);


        // validations
        $required_fields = array("product_name", "product_amount");
        validate_presences($required_fields);
        $fields_with_max_lenghts = array("product_name" => 30);
        validate_max_lenght($fields_with_max_lenghts);

        if(!empty($errors)){
            $_SESSION["errors"] = $errors;
            redirect_to("new_product.php");
        }
        if($result && $results ){
            // Sucess

            $_SESSION["message"] = "Product inserted.";
            redirect_to("manage_content.php");
        }else{
            // Failure

            $_SESSION["message"] = "Product insertion Failed.";
            redirect_to("new_product.php");
            }
        }
}else{
    // THis is probably a GET request
    redirect_to("new_product.php");
}
?>
<?php
if(isset($connnection)){
mysqli_close($connection);
}
?>

Just dumping code isn't going to work. Please explain what should but isn't happening.

i want to insert multiple images

<?php require_once("../includes/session.php");?>
<?php require_once("../includes/connection.php");?>
<?php require_once("../includes/function.php");?>
<?php confirm_logged_in();?>
<?php $layout_context ="admin";?>
<?php
include("../includes/layouts/header.php");
?>
<?php
find_selected_page();
?>
<div id="main">
  <div id="navigation">
   <?php
  echo navigation($current_subject,$current_page);
   ?>
  </div>
  <div id="page">
  <?php
  echo message();
  ?>
  <?php
  $errors = errors();
  ?>
  <?php
  echo form_errors($errors);
  ?>
  <h2>New  Product</h2>

  <form action="create_product.php" method="post" enctype="multipart/form-data">
  <p>
  <input type="text"   name="product_name"  value="" placeholder="Product Name:"  required="required" >
  </p>
   <p>
  <input type="text" name="product_amount" value="" placeholder="Product Amount:" required="required"  />
   <p>
   Select A File:
  <input type="file" name="files[]" multiple required="required"/>
  </p>
  <p>Visible:
  <input type="radio" name="visible" value="0" required="required"/>No
  <input type="radio" name="visible" value="1" required="required"/>Yes
   </p>
    <input type="submit" name="submit"  value="Insert Product"/>
    </form><br>
<a href="manage_content.php">Cancel</a>    
  </div>
</div>
<?php
include("../includes/layouts/footer.php");
?>
Member Avatar for iamthwee

So you want a multiple file upload script?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.