tphgangster Posted April 28, 2009 Share Posted April 28, 2009 How do i get the value of an input with php soo i can insert it in i.e. a for-loop? for($i=0;$ < $inp;$i++) {..} were $inp = value of an input. Anyone? // tphg Link to comment https://forums.phpfreaks.com/topic/155959-get-value-from-a-input-with-php/ Share on other sites More sharing options...
trq Posted April 28, 2009 Share Posted April 28, 2009 What? Link to comment https://forums.phpfreaks.com/topic/155959-get-value-from-a-input-with-php/#findComment-820961 Share on other sites More sharing options...
tphgangster Posted April 28, 2009 Author Share Posted April 28, 2009 Ok.. lets say i have <input type='text' value='32' /> How do i get 32 from that input so that i can use it in a loop, a php function, anything. exampel for($i=0;$i<=$value;$i++) {..} where $value is the value thats in the above input (32). for($i=0;$i<=32;$i++) {..} Link to comment https://forums.phpfreaks.com/topic/155959-get-value-from-a-input-with-php/#findComment-820989 Share on other sites More sharing options...
john-formby Posted April 28, 2009 Share Posted April 28, 2009 The example you posted should work: $value = 32; for($i = 0; $i<=$value; $i++) { echo $i.', '; } Link to comment https://forums.phpfreaks.com/topic/155959-get-value-from-a-input-with-php/#findComment-821004 Share on other sites More sharing options...
mrMarcus Posted April 28, 2009 Share Posted April 28, 2009 you must give that input (and any other input you plan on using), a name, ie. <input type="text" name="number" value="32" /> *replace "number" with whatever you want. btw, HTML prefers double-quotes (") as opposed to single-quotes ('). Link to comment https://forums.phpfreaks.com/topic/155959-get-value-from-a-input-with-php/#findComment-821010 Share on other sites More sharing options...
radi8 Posted April 28, 2009 Share Posted April 28, 2009 You need to use it from a POST operation. So, when the user enters the value and presses a button, you grab the value from the post values. Also, assume that the input field is defined as so: <form action= <?php echo $_SESSION['http'].$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; ?> <input name="txtVal" type="desc" id="txtval" size="15"> <input type="submit" name="btnProc" value="Process"> </form> if(isset($_POST['btnProc']) && $_POST['btnProc']=='Process'){ $value=(isset($_POST['txtVal'])?$_POST['txtVal']:0); if($value>0){ for($i = 0; $i<=$value; $i++) { echo $i.', '; } } } If you want it to work without the post form (form reload), then use javascript. Link to comment https://forums.phpfreaks.com/topic/155959-get-value-from-a-input-with-php/#findComment-821013 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.