0

I'm trying to edit images records from database. data fetching part is ok but my editing code not working. i modify this code using insert part. inserting to db is working but edit not working. i'm new to php. i want to add multiple images with form data for my Classified ads project.

on edit page...

<input type="file" name="upload[]" onchange="previewFiles()" multiple /> 

on edit processing page....

<?php $file_dir = "../images/"; if (!file_exists($file_dir)) { mkdir($file_dir, 0777, true); } if (isset($_POST["Input"])) { function diverse_array($array) { $result = []; foreach($array as $key1 => $value1) foreach($value1 as $key2 => $value2) $result[$key2][$key1] = $value2; return $result; } $file_multi = diverse_array($_FILES['upload']); for ($y = 0; $y < 4; $y++) { $image[$y] = ''; } for ($x = 0; $x < count($file_multi); $x++) { foreach ($file_multi[$x] as $key => $value) { $file_name = $file_multi[$x]['name']; $file_size = $file_multi[$x]['size']; $file_tmp = $file_multi[$x]['tmp_name']; $file_target = $file_dir . $file_name; $errors = array(); $file_secure = array('jpg', 'jpeg', 'png', 'gif', 'bmp'); $file_current = strtolower(pathinfo($file_name, PATHINFO_EXTENSION)); /* (end(explode('.', $file_name) */ if (in_array($file_current, $file_secure) === false) { $errors[] = "Sorry, <strong>{$file_current}</strong> extension not allowed"; } } if (!empty($errors)) { foreach ($errors as $keyError => $valueError) { echo "$keyError = $valueError <br />"; } } else { if (move_uploaded_file($file_tmp, $file_target)) { $image[$x] = $file_target; echo "<strong>{$file_name}</strong> has been uploaded." . "<br />"; } else { echo "Sorry, there was an something wrong in <b>move_uploaded</b>."; } } } if (!empty($errors)) { foreach ($errors as $keyError => $valueError) { echo "$keyError = $valueError <br />"; } } else { $id = $_POST['id']; $image1 = $image[0]; $image2 = $image[1]; require_once("koneksi.php"); $sql = "UPDATE post_gallery SET images1='$image1', images2='$image2' WHERE id='$id' "; $parameter = array( ':image1' => $image1, ':image2' => $image2); $query = $conn->prepare($sql); $query->execute($parameter); echo "Data succesfully inserted !!"; $conn = null; header("Location:../view-post.php?id=4"); } } else { header("Location:../view-post.php?id=4"); } ?> 
2
  • your code failed because you didn't use the proper syntax for the prepared statement you're wanting to use. To which is missing one in the array on top of that. Commented Feb 21, 2018 at 12:35
  • could you please update my code. Commented Feb 21, 2018 at 15:05

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.