Page 2 of 2

Posted: Sun Jun 22, 2003 2:07 pm
by I3lade
Ok, there arnt any error messages anymore.
I want it to say if u have a pet :
Error, you cannot make another pet!
And if you dont the stuff to create it.
So i did that code above which says if havepet is set to one it shows Sorry you cannont create another pet! and the else to show if its not 1 the stuff to make the pet. Right now all it shows is the stuff to make the pet even if its set to 1, whats wrong?

where

Posted: Sun Jun 22, 2003 2:14 pm
by phpScott
Where is havepet comming from. Is it a session variable or is comming from the db somewhere?

phpScott

Posted: Sun Jun 22, 2003 2:19 pm
by cactus
As a test check the variable has a value in before using it in your if statement and then see if its equal to 1:

Code: Select all

...
session_start();
if(isset($havepet))
{
   if($havepet==1) { 
      echo "You already have a pet, you cannot create another!";
   }else{ 
      // do your other stuff.
   }
} else {
   echo "havepet not set!";
   var_dump($havepet);
}
...
Regards,

Posted: Sun Jun 22, 2003 2:23 pm
by I3lade
Well havepet is a int feild in one of my database tables

Posted: Sun Jun 22, 2003 2:27 pm
by cactus
Can you guarantee that $havepet has a value, and that value is 1 ?

Echo out the variable or put more matching/testing in your script to handle the possible values of this variable.

Regards,

Posted: Sun Jun 22, 2003 2:29 pm
by I3lade
?Are you saying the feild in the db isnt right?

Posted: Sun Jun 22, 2003 2:43 pm
by cactus
No, just that the variable may not contain a value of 1, your if statement is matching something which obviously is'nt a value of 1.

As a test, echo out $havepet before the if (after you start your session) and see what it's value is:

Code: Select all

echo "havepet value = ".$havepet."<br />\n";
What is the value of this variable ?

Regards,

Posted: Mon Jun 30, 2003 10:00 am
by I3lade
Well, sorry to post this so late was on vacation, each persons value is different. The value is either 1 or 0 but when they fill out a form on a sperate page it sets the value to one. Mine was set to one but still thinks it's 0. Maby I need to get thier id or something otherwise it checks no row wihich would mean it would be 0, which is defualt.