rjusman90 Posted October 3, 2014 Share Posted October 3, 2014 <?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 More sharing options...
ginerjm Posted October 3, 2014 Share Posted October 3, 2014 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. Link to comment https://forums.phpfreaks.com/topic/291405-why-my-multiple-file-not-insert/#findComment-1492626 Share on other sites More sharing options...
Barand Posted October 3, 2014 Share Posted October 3, 2014 It often helps to echo $sql; and inspect the code that is actually being executed. Link to comment https://forums.phpfreaks.com/topic/291405-why-my-multiple-file-not-insert/#findComment-1492632 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.