Jump to content

Recommended Posts

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? 


Link to comment
https://forums.phpfreaks.com/topic/295922-arrays-and-loops/
Share on other sites

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";
            }
        }
       ?>
Link to comment
https://forums.phpfreaks.com/topic/295922-arrays-and-loops/#findComment-1510486
Share on other sites

 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)

Link to comment
https://forums.phpfreaks.com/topic/295922-arrays-and-loops/#findComment-1510513
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.