PDO条件问题

时间:2013-02-18 00:10:48

标签: php pdo conditional

我有一个部分,我希望用户能够发布评论,或发布评论与图像。我已经从一个查询变为两个试图使条件语句起作用。

此时,无论我是否有要上传的图像文件,都会忽略第一个查询。

谁能看到我哪里出错了?

谢谢

加里

<?php

$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));
    }
}
?>

0 个答案:

没有答案