ejsmith67 Posted August 20, 2006 Share Posted August 20, 2006 I am convrting a website from .ASP to .PHP and I have run into an isue I cannot resolve. I have a data entry form/table where the variable names are the same in each row. When submitting to a PHP page to write records teh query string is similia to belowhttp://post.php?parm123=1&parm2=123&parm3=123&parm1=234&parm2=234&parm3=234...In .ASP, in the receiving page I can extract the following :parm1 = 123,234,,,,,,parm2=123,234,,,,,parm3=123,234,,,,,and treat them as arraysin PHP when I go through the $_request, only the last value is available. Is there an extension I need ot a coding trick in PHP to get the query string into an arry, similiar to what .ASP does ??Thanks in advance for any amd all help. Link to comment Share on other sites More sharing options...
hitman6003 Posted August 20, 2006 Share Posted August 20, 2006 You are reusing the same variable name twice, so the latter instance will overwrite any earlier values.If you want to know exactly what is being passed in the url parameters, then do a print_r of the $_GET array.[code]echo '<pre>';print_r($_GET);[/code]Also, use $_POST and $_GET instead of $_REQUEST. Link to comment Share on other sites More sharing options...
ejsmith67 Posted August 21, 2006 Author Share Posted August 21, 2006 in the code I do use $_post, the $_request was used as follows : print("<pre>"); $count = count($_REQUEST); print("Number of values: $count\n"); foreach ($_REQUEST as $key=>$value) { print(" $key = $value\n"); } print("</pre></html>\n");to see what PHP was "seeing" as the variables...I determined how it is behaving by filling in the last line of the form ad seeing that those values survived.Is there any way to get PHP to behave like .ASP, in that, if the same variable name is used more than once, the $_post will treat the entries as an array ? Link to comment Share on other sites More sharing options...
ToonMariner Posted August 21, 2006 Share Posted August 21, 2006 php does just that... well teh browser does it regardless of the aqccepting script's language...providing you have set the name of the input like so...<input .... name="var[]" ....it is not the difference in language here its the methdo of returning the variables if you have a few inputs named as above then you coudl access them in the accepting script like so..print_r($_POST['var']);orforeach($_POST['var'] as $key => $val){ echo $key . " = " . $val;} Link to comment Share on other sites More sharing options...
ejsmith67 Posted August 21, 2006 Author Share Posted August 21, 2006 Here is the generated html form :[code]<TR bgcolor=#CCFF99><td><select name="iPItemNum[]"><option selected><option value="13">Artichokes<option value="25">Baby Clams<option value="14">Bacon<option value="54">Bill's Apple Bread Pudding<option value="58">Biscotti</select></td><td><select name="iPSizeNum[]"><option selected><option value="14">1 lb.<option value="15">3 lb.<option value="16">5 lb.<option value="13">8oz Cup</select></td><td><input type="text" name="iPrice[]" size="10"></tr>[/code]repeated 20 timestesting the receiving page with the code you provided :[code]foreach($_POST["iPItemNum"] as $key => $val){ echo $key . " = " . $val;} foreach($_POST["iPSizeNum"] as $key => $val){ echo $key . " = " . $val;} foreach($_POST["iPrice"] as $key => $val){ echo $key . " = " . $val;}[/code]yields no output, but the dump of the quiry string is :iPItemNum%5B%5D=13&iPSizeNum%5B%5D=16&iPrice%5B%5D=10.00&iPItemNum%5B%5D=54&iPSizeNum%5B%5D=17&iPrice%5B%5D=3.50I dont mean to be dense, but am I missing something ? Link to comment Share on other sites More sharing options...
ToonMariner Posted August 21, 2006 Share Posted August 21, 2006 sorry matey i used $_POST... you r sending via get so replace $_POST with $_GET Link to comment Share on other sites More sharing options...
ejsmith67 Posted August 21, 2006 Author Share Posted August 21, 2006 Thanks for the help, I'm gettng waht I need now. It was the '[]' in the form that is required for PHP that wasnt required for ASP Link to comment Share on other sites More sharing options...
Recommended Posts