Roy Barten Posted February 2, 2009 Share Posted February 2, 2009 I made a application where you can store hardware information etc. But i want different types of properties for every kind of hardware. So a laptop has the properties: memory Processor etc. and a mobile phone knows other property's like: Camera yes/no etc. I have to fill in this properties into a variable number of textfields. This information must be stored in a database. But because i have a variable number of textfields the names of the textfields are always different. Into the next page i have to open this information with a post, but how do i call this textfields? Can i place a variable into a $_POST? Like this $_POST[$name]? Link to comment https://forums.phpfreaks.com/topic/143440-solved-variable-inside-a-_post/ Share on other sites More sharing options...
Mchl Posted February 2, 2009 Share Posted February 2, 2009 Yes, you can. Just like with all other arrays. Link to comment https://forums.phpfreaks.com/topic/143440-solved-variable-inside-a-_post/#findComment-752394 Share on other sites More sharing options...
trq Posted February 2, 2009 Share Posted February 2, 2009 Can i place a variable into a $_POST? Like this $_POST[$name]? Of course, but you'll likely not need to. Just name your text fields as array elements. eg; <input type="text" name="property[]"> <input type="text" name="property[]"> <input type="text" name="property[]"> Then, on the recieving page they will be in the array $_POST['property']. You can then loop through this array. Link to comment https://forums.phpfreaks.com/topic/143440-solved-variable-inside-a-_post/#findComment-752396 Share on other sites More sharing options...
Roy Barten Posted February 2, 2009 Author Share Posted February 2, 2009 Oke, i've tried something but it does not work, so i have create 2 testfiles with the following code: test.php <? $naam = "txttest"; ?> <form id="form1" name="form1" method="post" action="uitkomst.php"> <label> <input type="text" name= "<? $naam ?>" /> </label> <label> <input type="submit" name="Submit" value="Submit" /> </label> </form> and uitkomst.php <? $naam = "txttest"; echo $_POST[$naam]; ?> This is only a testfile but the weppage does not echo anything, so something is wrong but what? ??? Link to comment https://forums.phpfreaks.com/topic/143440-solved-variable-inside-a-_post/#findComment-752397 Share on other sites More sharing options...
trq Posted February 2, 2009 Share Posted February 2, 2009 The only thing I can see wrong there is your using short php tags. Link to comment https://forums.phpfreaks.com/topic/143440-solved-variable-inside-a-_post/#findComment-752399 Share on other sites More sharing options...
Roy Barten Posted February 2, 2009 Author Share Posted February 2, 2009 yes, but this is not the problem, I always use short php tags, but the page does not show anything. Maybe a syntax error somewhere? I can't see it! Link to comment https://forums.phpfreaks.com/topic/143440-solved-variable-inside-a-_post/#findComment-752400 Share on other sites More sharing options...
trq Posted February 2, 2009 Share Posted February 2, 2009 This line... <input type="text" name= "<? $naam ?>" /> should be.... <input type="text" name="<? $naam ?>" /> to make it valid html. Otherwise, I don't see a problem. I think however youv'e missed the point of my last few replies. Firstly, short tags shouldn't be used, there not portable. And secondly, if your creating a variable amount of text inputs your better off naming them using arrays in the first place. Link to comment https://forums.phpfreaks.com/topic/143440-solved-variable-inside-a-_post/#findComment-752402 Share on other sites More sharing options...
Roy Barten Posted February 2, 2009 Author Share Posted February 2, 2009 I will try something with those array's. Thank's for you're help! Link to comment https://forums.phpfreaks.com/topic/143440-solved-variable-inside-a-_post/#findComment-752405 Share on other sites More sharing options...
Mchl Posted February 2, 2009 Share Posted February 2, 2009 How about echoing a variable? <input type="text" name="<? echo $naam ?>" /> Link to comment https://forums.phpfreaks.com/topic/143440-solved-variable-inside-a-_post/#findComment-752406 Share on other sites More sharing options...
trq Posted February 2, 2009 Share Posted February 2, 2009 How about echoing a variable? <input type="text" name="<? echo $naam ?>" /> Oh yeah. Indeed. I don't use short tags so didn't even notice. <input type="text" name="<?= $naam ?>" /> Link to comment https://forums.phpfreaks.com/topic/143440-solved-variable-inside-a-_post/#findComment-752407 Share on other sites More sharing options...
Roy Barten Posted February 2, 2009 Author Share Posted February 2, 2009 How about echoing a variable? <input type="text" name="<? echo $naam ?>" /> Oh yeah. Indeed. I don't use short tags so didn't even notice. <input type="text" name="<?= $naam ?>" /> GREAT!! It works!!! Thank you!!! Link to comment https://forums.phpfreaks.com/topic/143440-solved-variable-inside-a-_post/#findComment-752411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.