Jump to content

Recommended Posts


<?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);
}
?>

new_product.php

create_product.php

Link to comment
https://forums.phpfreaks.com/topic/291405-why-my-multiple-file-not-insert/
Share on other sites

Why do you use php tags for every statement?  Rather silly.  Turn it on.  Turn if off. Turn it on. Turn if off.  Talk about code bloat!

 

Turn on error checking (see my signature).  Add checks of your query calls to ensure that they ran. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.