Hello i am trying to check to see if there is a row in the db but for some resson it keeps saying there is but is not. I have loads of if staments in side one so i think that is the problem.
<?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 ;
}
?>
The bit which keeps printing true is
<?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";
}
?>
I remove all rows but still says You have this item
mysql_num_rows()
gets a mysql result type resource, use $query = mysql_query($query)
before mysql_num_rows
You have an error in your if statement. If the number of rows returned are > 0, you're printing "You do not have this item". It should be the other way around, so change the !=
check or let the echoes switch places