Jump to content

[SOLVED] Why isn't my $_POST less than working...?


Alexhoward

Recommended Posts

Hi Guys,

 

sure i'm doing something stupid here.

 

so, i've got a form :

 

for example :

<form method='post' action='page2'>
<input type='text' name='amount' value='0.00' style='width: 60px'>
</form>

 

the user enters an amount

 

then i pick it up :

 

<?php
if($_POST['amount'] < 5 ) {
this
}
else {
this
}
?>

 

but it doesn't seem to matter what amount i put in it always thinks it less than 5...?

 

could anyone help me?

 

Thanks in advance!

Link to comment
Share on other sites

Hi Guys,

 

sure i'm doing something stupid here.

 

so, i've got a form :

 

for example :

<form method='post' action='page2'>
<input type='text' name='amount' value='0.00' style='width: 60px'>
</form>

 

the user enters an amount

 

then i pick it up :

 

<?php
if(floatval($_POST['amount'])) < 5 ) {
this
}
else {
this
}
?>

 

but it doesn't seem to matter what amount i put in it always thinks it less than 5...?

 

could anyone help me?

 

Thanks in advance!

 

Try that? Duno if it will work...

Link to comment
Share on other sites

Could it be that <input type='text' name='amount' value='0.00' style='width: 60px'> is actually sending 0.00?

Have you tried <input type='text' name='amount' value='' style='width: 60px'> ?

 

just a thought...

 

having something in the value attribute simply assigns a default.  If the user enters something into the form it will overwrite it.

Link to comment
Share on other sites

Hi Guys,

 

Thanks for the feedback

 

the code above above is just an example...

 

i've echoed the post an it's coming back fine, as in whatever you type in..

 

the floatval made no difference... but thanks that's something i didn't know

 

i've tried it without the value='0.00' ... no difference

 

is it something to do with the way i'm saying :

 

if($_POST['amount'] < 5 )

Link to comment
Share on other sites

This works just fine:

 

<?php 
if ($_POST['amount'] < 5) {
  echo "less than 5";
} else {
  echo "more than 5";
}
?>

<form method='post' action=''>
<input type='text' name='amount' value='0.00' style='width: 60px'>
<input type='submit' value='submit'>
</form>

 

You're going to have to show your actual code not just some example.

Link to comment
Share on other sites

Hi Guys,

 

Think I've sorted it...

 

I was running a redirect if the amount was less than 5 to bring up an error message,

 

don't think i had it quite right in the IF statment, so whatever the out come it would always redirect with the error.

 

sorry to waste your time, you know how it gets starting at code for too long

 

 

Thankyou all for your input!

 

apologies again

Link to comment
Share on other sites

OK,

 

it's just stuck in a load of other code,

 

so i'll just pull out the bits that are relevant :

 

input page

<form method='post' action='adamount.php'>
<td>
Please enter the required amount * : £ <input type='text' name='amount' value='0.00' style='width: 60px'> $error
</td>
<tr>
<td align='right'>
<input type='submit' name='go' value='Submit' />
</td>
</tr>
</form>

 

and the adamount.php page :

<?php

//$_POST['amount'] = mysql_real_escape_string($_POST['amount']);

//check amount over £5 has been entered
if($_POST['amount'] < 5 ) {
header( 'Location: http://www.mysite.co.uk/folder1/folder2/inputpage.php?error=1' ) ;
exit;
}

else {

some code here

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.