Php Wordpress和SQL,比较条件

Php Wordpress和SQL,比较条件,php,mysql,wordpress,Php,Mysql,Wordpress,我想比较一下postType <input name="postType" value="" id="postType" required> 所以,如果我将页面放入输入中,它将返回正确的结果 我对一般情况所做的: $term = $_POST["postType"]; $result = $wpdb->get_results("SELECT count(ID) FROM $wpdb->posts WHERE post_type = '".$term."')"); for

我想比较一下postType

<input name="postType" value="" id="postType" required>
所以,如果我将页面放入输入中,它将返回正确的结果

我对一般情况所做的:

$term = $_POST["postType"];
$result = $wpdb->get_results("SELECT count(ID) FROM $wpdb->posts WHERE post_type = '".$term."')");
foreach($result as $resultX) {
    if($_POST["postType"] == $resultX) {
        //results
    }
}

但它不起作用

你能详细说明一下,但它不起作用吗?你有错误吗?错误的结果?您似乎在SQL中添加了一个错误,这应该会导致错误。您正在使用SELECT countID检索一个数值,但似乎需要一个数组。您没有提供类型=。。。对于您的输入字段,您的sql/php是完全开放的。您是否进行过任何基本调试,如var_dump$_POST,以查看脚本接收到的内容?感谢sql注入建议。我做了var_转储,但无法获取结果项。忽略这个问题,我已经纠正了。错误的结果没有显示我想要的,它什么也没有显示。是的,countID错了。如何更改为从post_类型返回字符串并进行比较?
$term = $_POST["postType"];
$result = $wpdb->get_results("SELECT count(ID) FROM $wpdb->posts WHERE post_type = '".$term."')");
foreach($result as $resultX) {
    if($_POST["postType"] == $resultX) {
        //results
    }
}