Alexhoward Posted October 11, 2008 Share Posted October 11, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/ Share on other sites More sharing options...
Andy-H Posted October 11, 2008 Share Posted October 11, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662731 Share on other sites More sharing options...
Maq Posted October 11, 2008 Share Posted October 11, 2008 Echo $_POST['amount'] out to make sure it has the right value. Also put error checking on. Add this on the top of your script: ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662733 Share on other sites More sharing options...
Shaun Posted October 11, 2008 Share Posted October 11, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662735 Share on other sites More sharing options...
JasonLewis Posted October 11, 2008 Share Posted October 11, 2008 What? That should be giving you a parse error. And why is your forms action to a page with no extension? Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662737 Share on other sites More sharing options...
Maq Posted October 11, 2008 Share Posted October 11, 2008 Like project said: </pre> <form method="'post'" action="'page2.php'"> < You should really post the full amount of code. Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662742 Share on other sites More sharing options...
.josh Posted October 11, 2008 Share Posted October 11, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662743 Share on other sites More sharing options...
Alexhoward Posted October 11, 2008 Author Share Posted October 11, 2008 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662745 Share on other sites More sharing options...
.josh Posted October 11, 2008 Share Posted October 11, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662753 Share on other sites More sharing options...
JasonLewis Posted October 11, 2008 Share Posted October 11, 2008 Maybe post the actual code instead of an example. (Yeah, what CV said.) Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662754 Share on other sites More sharing options...
Alexhoward Posted October 11, 2008 Author Share Posted October 11, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662760 Share on other sites More sharing options...
Alexhoward Posted October 11, 2008 Author Share Posted October 11, 2008 No Wait! it wasn't that...!! i'd commented out the real_escape_string! so how can i protect myself if i can't use real escape....?!? Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662762 Share on other sites More sharing options...
.josh Posted October 11, 2008 Share Posted October 11, 2008 You can use it just fine. You probably aren't using it right. Or something else is wrong with your code. Again, post your code. Seriously, doesn't it make sense that if you want help with code, to post the code? Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662769 Share on other sites More sharing options...
LemonInflux Posted October 11, 2008 Share Posted October 11, 2008 <?php if ((int) $_POST['amount'] < 5) { echo "less than 5"; } else { echo "more than 5"; } ?> ---------------- Now playing: Elbow - An Audience With the Pope via FoxyTunes Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662770 Share on other sites More sharing options...
.josh Posted October 11, 2008 Share Posted October 11, 2008 <?php if ((int) $_POST['amount'] < 5) { echo "less than 5"; } else { echo "more than 5"; } ?> ---------------- Now playing: Elbow - An Audience With the Pope via FoxyTunes Yeah that works awesome if the expected value is supposed to be an int. But I have a sneaking suspicion that since his default is a float... Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662773 Share on other sites More sharing options...
Alexhoward Posted October 11, 2008 Author Share Posted October 11, 2008 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662774 Share on other sites More sharing options...
LemonInflux Posted October 11, 2008 Share Posted October 11, 2008 oh yeah. sorry, it's been a long week. ---------------- Now playing: Elbow - An Audience With the Pope via FoxyTunes Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662776 Share on other sites More sharing options...
.josh Posted October 11, 2008 Share Posted October 11, 2008 Alex: So you're saying that no matter what, you are being directed to that header location? Are you sure it's that one, and not maybe some other header in your code, or something? Because there is no reason why that condition should evaluate true if you enter in something > 5 Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662779 Share on other sites More sharing options...
Alexhoward Posted October 11, 2008 Author Share Posted October 11, 2008 Hi, As i've just realised, it all works fine with the real_escape commented out however, i obviously want to protect against sql injection and the like but when i turn it on it doesn't work anymore.... any ideas...? thanks for all this Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662782 Share on other sites More sharing options...
Andy-H Posted October 11, 2008 Share Posted October 11, 2008 floatval() Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662785 Share on other sites More sharing options...
Alexhoward Posted October 11, 2008 Author Share Posted October 11, 2008 That isn't working mate...??? Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662791 Share on other sites More sharing options...
Alexhoward Posted October 11, 2008 Author Share Posted October 11, 2008 Sorted It was because i was doing the real_escape thing before connecting to the database and it didn't like that... so moved it and it works now thanks for all your help guys! Quote Link to comment https://forums.phpfreaks.com/topic/127986-solved-why-isnt-my-_post-less-than-working/#findComment-662839 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.