Php Mysql行始终=1

Php Mysql行始终=1,php,mysql,sql,Php,Mysql,Sql,您好,我正在检查数据库中是否有行,但对于某些resson,它一直说有行,但没有行。我在第一面有很多if语句,所以我认为这就是问题所在 <?php if (isset($_POST['A'])) { $item2= mysql_real_escape_string($_POST['A']); $item = strip_tags($item2); $pokemonchoice= mysql_real_escape_string($_POST['B']); $pokemonchoicee

您好,我正在检查数据库中是否有行,但对于某些resson,它一直说有行,但没有行。我在第一面有很多if语句,所以我认为这就是问题所在

<?php
 if (isset($_POST['A'])) {
$item2= mysql_real_escape_string($_POST['A']);
$item = strip_tags($item2);

$pokemonchoice= mysql_real_escape_string($_POST['B']);
$pokemonchoicee = strip_tags($pokemonchoice);



?><?php  
 if ( $pokemonchoicee == "Add to pokemon 1" ) {
    $pokemonchoicee = '1';
}
 if ( $pokemonchoicee == "Add to pokemon 2" ) {
    $pokemonchoicee = '2';
}
 if ( $pokemonchoicee == "Add to pokemon 3" ) {
    $pokemonchoicee = '3';
}
 if ( $pokemonchoicee == "Add to pokemon 4" ) {
    $pokemonchoicee = '4';
} 
 if ( $pokemonchoicee == "Add to pokemon 5" ) {
    $pokemonchoicee = '5';
}
 if ( $pokemonchoicee == "Add to pokemon 6" ) {
    $pokemonchoicee = '6';
}

 ?>

 <?php


 $query = "SELECT * FROM items WHERE item='".$item."' AND belongsto='".$_SESSION['username']."'";
if(mysql_num_rows($query)!=0)
{
echo "You do not have this item";
}
else
{
echo "You have this item";
}

 ?>

 <?php
 echo $pokemonchoicee ;
 echo $item ;
 }

 ?>


mysql\u num\u rows()
获取一个mysql结果类型资源,在mysql\u-rows之前使用
$query=mysql\u-query($query)
mysql\u-rows()
获取一个mysql结果类型资源,在mysql\u-rows之前使用
$query=mysql\u-query($query)
您的if语句中有一个错误。如果返回的行数大于0,则打印“您不拥有此项目”。它应该是另一种方式,所以更改
=检查或让回声切换位置

如果if语句中有错误。如果返回的行数大于0,则打印“您不拥有此项目”。它应该是另一种方式,所以更改
=检查或让回声切换位置

或者,您可以使用mysql\u num\u rows(mysql\u query($query))只需阅读您的编辑,现在它就可以工作感谢;或者,您可以使用mysql\u num\u rows(mysql\u query($query))只需阅读您的编辑,现在它就可以工作感谢,直到项目出现时您没有此项目,,,更改该行当然会给您另一条回显消息。当项目存在时,您仍然没有此项目,,,更改该行当然会给您另一条回显消息。
 <?php


 $query = "SELECT * FROM items WHERE item='".$item."' AND belongsto='".$_SESSION['username']."'";
if(mysql_num_rows($query)!=0)
{
echo "You do not have this item";
}
else
{
echo "You have this item";
}

 ?>