Reputation: 280
In my post page i have multiple upload fields.
<form action="" method="post" enctype="multipart/form-data"
class="form-horizontal">
<div class="form-group col-md-5">
<label for="image">Big pic</label>
<input id="image" type="file" name="image" class="btn btn-danger">
</div>
<div class="form-group col-md-5">
<label for="img_v1">V1</label>
<input id="img_v1" type="file" name="img_v1" class="btn btn-danger">
</div>
<div class="form-group col-md-5">
<label for="img_v2">V2</label>
<input id="img_v2" type="file" name="img_v2" class="btn btn-danger">
</div>
And i want to upload each field to each row in my server.
my upload script is in the same file.
$error = '';
if(isset($_POST['submit_post'])){
$title = strip_tags($_POST['title']);
$date = date('Y-m-d h:i:s');
if($_FILES['image']['name'] !=''){
$image_name = $_FILES['image']['name'];
$image_tmp = $_FILES['image']['tmp_name'];
$image_size = $_FILES['image']['size'];
$image_ext = pathinfo($image_name,PATHINFO_EXTENSION);
$image_path = '../clientes/img/'.$image_name;
$image_db_path = 'img/'.$image_name;
if($image_size < 10000000){
if($image_ext == 'jpg' || $image_ext == 'png' || $image_ext == 'jpeg' || $image_ext == 'gif'){
if(move_uploaded_file($image_tmp,$image_path)){
$ins_sql = "INSERT INTO gallery (title, description, image, category, status) VALUES ('$title', '$_POST[description]',
'$image_db_path', '$_POST[category]', '$_POST[status]')";
if(mysqli_query($conn,$ins_sql)){
header('post_list.php');
}else{
$error = '<div class="alert alert-danger">Erro de script</div>';
}
}else{
'<div class="alert alert-danger">Image cant upload</div>';
}
}else{
$error = '<div class="alert alert-danger">Wrong image extention</div>';
}
}else{
$error = '<div class="alert alert-danger">Image is to much big</div>';
}
}else{
$ins_sql = "INSERT INTO gallery (title, description, category, status, date, author) VALUES ('$title', '$_POST[description]',
'$_POST[category]', '$_POST[status]', '$date', '$_SESSION[userName] $_SESSION[userLName]')";
if(mysqli_query($conn,$ins_sql)){
header('post_list.php');
}else{
$error = '<div class="alert alert-danger">Script error</div>';
}
}
}
i tried to upload the 3 fields to the server like this...
INSERT INTO gallery (title, description, image,img_v1, img_v2 category, status) VALUES ('$title', '$_POST[description]', '$image_db_path','$image_db_path','$image_db_path', '$_POST[category]', '$_POST[status]')";
But i know it was wrong. What i have to do so i can upload the extra img fields?
Upvotes: 0
Views: 96
Reputation: 1171
You missed one comma between img_v2 and category.
INSERT INTO gallery (title, description, image,img_v1, img_v2, category, status) VALUES ('$title', '$_POST[description]', '$image_db_path','$image_db_path','$image_db_path', '$_POST[category]', '$_POST[status]')";
Upvotes: 1