traymonds Posted April 28, 2015 Share Posted April 28, 2015 Hi: I'm new to PHP and struggling to figure out how to perform the last 2 bullets.... - Use POST function to retrieve inputs from 3 HTML text boxes - containing values within the range 0.0–10.0. - Place the values in an array, and then do a loop to search the array and validate the input. - Display results back to the browser confirming whether the input is valid. Can anyone help? Quote Link to comment Share on other sites More sharing options...
requinix Posted April 28, 2015 Share Posted April 28, 2015 (edited) What's your full code so far? What have you tried? How did it not work? Edited April 28, 2015 by requinix Quote Link to comment Share on other sites More sharing options...
venkatpvc Posted May 1, 2015 Share Posted May 1, 2015 With respect to requinix replay; can this help to you? <?php $arr = array(); if (isset($_POST['submit'])) { foreach($_POST as $key=>$value) { if ($value != 'submit') { if ($value >= 0.0 && $value <= 10.0) { $arr[$key] = $value; } } } foreach($arr as $key=>$val) { echo $key." Value inserted by User: <strong>".$val."</strong>\n"; } } ?> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 1, 2015 Share Posted May 1, 2015 So? What's wrong with this code? Looks fine to me. Quote Link to comment Share on other sites More sharing options...
nik_jain Posted May 1, 2015 Share Posted May 1, 2015 POST variables are returned as String afaik, so they needs to be converted into integer for integer comparison So this should do the job: if ((int)$value >= 0.0 && (int)$value <= 10.0) { Quote Link to comment Share on other sites More sharing options...
CroNiX Posted May 1, 2015 Share Posted May 1, 2015 POST variables are returned as String afaik, so they needs to be converted into integer for integer comparison So this should do the job: if ((int)$value >= 0.0 && (int)$value <= 10.0) { Except you probably don't want to cast floats as integers, or 5.5 will be the same as 5.2 (both would be just 5) Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 1, 2015 Share Posted May 1, 2015 Actually, as coded the comparison test works just fine. Quote Link to comment 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.