I have a section where I want a user to be able to post a comment, or post a comment with an image. I have gone from one query to two trying to get the conditional statement to work.
At this point, the first query is ignored whether I have an image file to upload or not.
Can anyone see where I am going wrong?
Thank You
Gary
PHP Code:$image = $_POST['image'];
if(isset($_POST['image'])){ // have had if(isset($_POST['com'])) did not work either
$comments = trim($_POST['comments']);
$image_file = $_FILES['image']['name'];
$image_type = $_FILES['image']['type'];
$image_size = $_FILES['image']['size'];
if(!empty($image_file)){
if (($image_type == 'image/gif') || ($image_type == 'image/jpeg') || ($image_type == 'image/pjpeg') || ($image_type == 'image/png') && ($image_size < 3000000)) {
if ($_FILES['image']['error'] == 0) {
// Move the file to the target upload folder
$target = 'imagesmemorial'. '/' . $image_file;
if(move_uploaded_file($_FILES['image']['tmp_name'], $target)){
$sqlic = "INSERT INTO uimages (userid, mem_id, image, comments) VALUES (:userid, :mem_id, :image, :comments)";
$qic = $conn->prepare($sqlic);
$qic->execute(array(':userid'=> $userid_m, ':mem_id'=>$mem_id, ":image"=>$image_file, ':comments'=>$comments));
}
}
}
}
}else{
if(isset($_POST['com']) && !isset($_POST['images'])){ // have had set as empty()
$comments = trim($_POST['comments']);
$sqlicn = "INSERT INTO uimages (userid, mem_id,comments) VALUES (:userid, :mem_id, :comments)";
$qicn = $conn->prepare($sqlicn);
$qicn->execute(array(':userid'=> $userid_m, ':mem_id'=>$mem_id, ':comments'=>$comments));
}
}



Reply With Quote

Bookmarks