Page 1 of 1

user submits a form with the value of textfield being 15000

Posted: Tue Jun 10, 2003 11:58 am
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.

What is the value

Posted: Tue Jun 10, 2003 12:00 pm
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

Posted: Tue Jun 10, 2003 7:48 pm
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.

Posted: Tue Jun 10, 2003 8:34 pm
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)

Posted: Tue Jun 10, 2003 10:39 pm
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,

Posted: Wed Jun 11, 2003 3:18 am
by twigletmac