flashbot Posted March 18, 2007 Share Posted March 18, 2007 Hi everyone, I have a simple query but due to my lack of php knowledge, can't find the right function. Let's say I have a form with 3 input fields. [field1] => 'hello' [field2] => 'ok' [field3] => 'goodbye' When I submit the page, I would like to echo this result: [field1] [field2] [field3] In other words, I want to have control over the posted header to determine if I should input in database the variable or not. If I use $HTTP_POST_VARS it actually returns the variable inside the header... i actually need the header's name. Thanks in advance, Sebastian. Link to comment https://forums.phpfreaks.com/topic/43286-solved-simple-post-query-help-needed/ Share on other sites More sharing options...
Gruzin Posted March 18, 2007 Share Posted March 18, 2007 try something like this: echo $_POST['field1']."<br>"; echo $_POST['field2']."<br>"; echo $_POST['field3']; actually I don't understand what do u mean under "header's name"? Regards, George Link to comment https://forums.phpfreaks.com/topic/43286-solved-simple-post-query-help-needed/#findComment-210181 Share on other sites More sharing options...
flashbot Posted March 18, 2007 Author Share Posted March 18, 2007 Hi George, Sorry, probably not using the right technicality here. I should probably summarize my problem: Keep in mind the "Gmail method for adding another attachment". I'm developing the same system on a site. I have 1 input field and a link "add another color". JS takes care of adding another input field and dynamically giving it a name value. When I submit the page, I need to collect only the name values relating to the input fields and input them in the database. Example, inputfield 1 will have name=color1(dynamically) and value=green inputfield 2 will have name=color2(dynamically) and value=red inputfield 3 will have name=color3(dynamically) and value=brown Problem is, as it is named dynamically, I don't actually know their names to invoke them as $thename = $_POST['thename']. So what I figured I should do, is retrieve all the post variables, check if each POST's name contains the word "color", if it does, input into database. Anyone can suggest a better method or knows the function I am so persistently after? Thanks! Sebastian Link to comment https://forums.phpfreaks.com/topic/43286-solved-simple-post-query-help-needed/#findComment-210184 Share on other sites More sharing options...
per1os Posted March 18, 2007 Share Posted March 18, 2007 foreach ($_POST as $key => $val) { if (ereg("color", $key)) { // do something here } } Link to comment https://forums.phpfreaks.com/topic/43286-solved-simple-post-query-help-needed/#findComment-210214 Share on other sites More sharing options...
flashbot Posted March 19, 2007 Author Share Posted March 19, 2007 foreach ($_POST as $key => $val) { if (ereg("color", $key)) { // do something here } } Thanks a lot Frost110, you have quite solved it. Sebastian Link to comment https://forums.phpfreaks.com/topic/43286-solved-simple-post-query-help-needed/#findComment-210232 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.