user submits a form with the value of textfield being 15000

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
mickey
Forum Newbie
Posts: 24
Joined: Thu May 01, 2003 11:14 am
Location: Philippines

user submits a form with the value of textfield being 15000

Post by mickey »

hi,

i am trying to do this on the result page which doesn't work,

if($loan < 150000)
{
}
else if($loan < 250000)
{
}
else
{
}

whatever value i place, it just evaluate to the first if.

i tried other methods like settype, casting it, even intval($loan), it just won't work...

any ideas? i need to compare tha value the user inputted on the form,

many thanks.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

What is the value

Post by phpScott »

What is the value of loan?

Try echoing out loan(if you haven't already) to make sure that it aleast laon has a value.

It is possible that loan isn't being passed back correctly to the page.

phpScott
mickey
Forum Newbie
Posts: 24
Joined: Thu May 01, 2003 11:14 am
Location: Philippines

Post by mickey »

the value is correct, if i pass 10000, then 10000 it is,

if i use intval() on the variable, it becomes zero....

thanks.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<html>
	<body>
<?php
	if(isset($_POST['loan']))
	{
		if($_POST['loan'] < 150000)
		{
			echo 'less than 150k';
		}
		else if($_POST['loan'] < 250000)
		{
			echo 'less than 250k';
		}
		else
		{
			echo 'more than or 250k';
		}		
	}
?>
		<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
			<input type="text" name="loan" id="loan" /><label for="loan">loan</label><br />
			<input type="submit" />
		</form>
	</body>
</html>
works fine for me (with $_POST since register_globals is off on my system)
mickey
Forum Newbie
Posts: 24
Joined: Thu May 01, 2003 11:14 am
Location: Philippines

Post by mickey »

hello volka,

it works! but i hope you don't mind, can you explain what happened there with the $_POST thing?

also, the php sdk states that we can just use the comparison operator and php will automatically convert variables to ints if it's a string.. but how come it doesn't work? hmm.., maybe this is where _POST comes in..

anyway, hoping for your explanation.

many thanks,
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Post Reply