我的查询在php中返回null但在mysql workbench中它确实返回一个值

时间:2014-05-13 22:06:45

标签: php mysqli param

此外,如果我不在代码中使用'die',我会在几秒钟后重定向到“不可用的页面”。

这是我的代码:

if(filter_input(INPUT_POST,'send')){
   $con2 = new mysqli('localhost', 'root', '', 'mafioso') or die("error");
   $sender = filter_input(INPUT_POST,'sender');
   $subject = filter_input(INPUT_POST,'subject');
   $message = filter_input(INPUT_POST,'message');
   if(strlen($message) > 5){
        $stmtCheckSender = $con2 -> prepare("SELECT `id` FROM `tbl_users` WHERE `username` = ? ");
        $stmtCheckSender -> bind_param('s', $sender);
        $stmtCheckSender -> execute();
        $stmtCheckSender -> bind_result($getSender2);
        if($getSender2 == NULL){
                var_dump($getSender2); die;
                $message2 = "The user to who you want to send the message doesn't exist.";
             }else{ 
            while($stmtCheckSender -> fetch()){
                 $senderExists = $getSender2;
                 break;
            }
             $stmtCheckSender -> close();

            $stmtSendMessage = $con -> prepare("INSERT INTO `tbl_messages`(`idreceiver`, `subject`, `message`, `idsender`) values (?, ?, ?, ?)");
            $stmtSendMessage -> bind_param('issi', $senderExists, $subject, $message, $_SESSION['userID']);
            $stmtSendMessage -> execute();
       }
   }else{
       $message2 = "The message is too short!";
   }
}

谢谢!

0 个答案:

没有答案