soy principiante y estoy tratando de guardar la ruta del directorio en la base de datos pero me sale un error que no eh podido resolver les comparto el codigo de antemano gracias. ERROR "Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined "
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$title = inputClear($_POST['title']);
$price = inputClear($_POST['price']);
$description = $_POST['description'];
$img = $_FILES['img']['tmp_name'];
$images = $_FILES['images']['tmp_name'];
$options = $_POST['options'];
$load_img = '../'.$realstate_config['folder_img'] . $_FILES['img']['name'];
move_uploaded_file($img, $load_img);
$statement = $conection->prepare('INSERT INTO houses (id, title, price, description, img, category_id) VALUES (null, :title, :price, :description, :img, :options)');
$statement->execute(array(
':title' => $title,
':price' => $price,
':description' => $description,
':img' => $_FILES['img']['name'],
':options' => $options
));
$last_id = $conection->lastInsertId();
$folder_name = '../'.$realstate_config['folder_img'] .$last_id.'/';
if(!empty($_FILES['images'])) {
if(!file_exists($folder_name)) {
mkdir($folder_name, 0777);
}
foreach($_FILES['images']['tmp_name'] as $key => $value) {
if(file_exists($_FILES['images']['tmp_name'][$key])) {
move_uploaded_file($images[$key], $folder_name.$_FILES['images']['name'][$key]);
}
}
$statement = $conection->prepare("UPDATE houses SET (folder_img) = ('.$folder_name.') WHERE id = $last_id");
$statement->execute(array(
':images' => $_FILES['images']['name']*---------- AQUI MARCA EL ERROR ---------*/
));
}
Ya intente con
$statement = $conection->prepare("UPDATE houses SET (folder_img) = ($folder_name) WHERE id = $last_id");
$statement->execute(array(
':images' => $_FILES['images']['name'],
':id' => $last_id
));
TAMBIEN agregando los dos puntos para indicar el placeholder
$statement = $conection->prepare("UPDATE houses SET (:folder_img) = ($folder_name) WHERE id = :$last_id");
$statement->execute(array(
':images' => $_FILES['images']['name'],
':id' => $last_id
));
Pero el error persiste
execute()
. Observa bien la respuesta que te dieron, el array que va en execute tiene un elemento':folder_img'=>$_FILES['images']['name']
y no':images'=>...
como tu código.