PHP Newbie - IF statement problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MattH_PHP
Forum Newbie
Posts: 5
Joined: Tue Sep 21, 2010 9:19 am

PHP Newbie - IF statement problem

Post by MattH_PHP »

Hi,

I'm new to PHP and have come up against a brick wall with an if statement.

I have an activation form that users need to complete to activate a membership card. When activation is successful, their details are stored in a MYSQL DB.

At the moment, the field that they need to enter the unique membership card number in can accept any number so i need to change it so that only numbers within a certain range will be accepted. The range is 60006000 to 60011000. This is the code is have done myself:

if ($_POST['$TWnumberfoundonmembershipcard'] < "60006000" or $_POST['$TWnumberfoundonmembershipcard'] > "60011000") {
die('The TW number you have entered is not valid. Please click the back button and re-enter the number ensuring the TW prefix is removed.');
}

Needless to say, it doesn't work. It just takes me to the die message no matter what number i enter. This is obviously something to do with my IF statement being wrong so has anybody got any ideas on where i'm going wrong?

Matt
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

Re: PHP Newbie - IF statement problem

Post by buckit »

OR = ||

if(1 == 2 || 2 == 3){
do something
}


another problem is your post variable isnt correctly formatted.

you have $_POST['$TWnumberfoundonmembershipcard']. it should be $_POST['theNameOfYourFormField'] not sure why you have the $ in there. if you named your form field with a $... take it out. you only use that if you are creating a variable.

so you could do:

$TWnumberfoundonmembershipcard = $_POST['membershipCardNumber'];

if ($TWnumberfoundonmembershipcard < 60006000 || $TWnumberfoundonmembershipcard > 60011000){
do something
}
Last edited by buckit on Tue Sep 21, 2010 10:28 am, edited 1 time in total.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: PHP Newbie - IF statement problem

Post by McInfo »

Is this literal?

Code: Select all

$_POST['$TWnumberfoundonmembershipcard']
If it is, that might be the problem. What is the actual name on the associated form input ?
MattH_PHP
Forum Newbie
Posts: 5
Joined: Tue Sep 21, 2010 9:19 am

Re: PHP Newbie - IF statement problem

Post by MattH_PHP »

Hi buckit,

Taking the $ out has solved the issue! Thanks so much, i've been banging my head against a wall for a few hours with this!

Matt
MattH_PHP
Forum Newbie
Posts: 5
Joined: Tue Sep 21, 2010 9:19 am

Re: PHP Newbie - IF statement problem

Post by MattH_PHP »

HI Mcinfo,

It was an error on my part. I just copied the variable name which had the $.

Matt
Post Reply