hyster Posted January 19, 2013 Share Posted January 19, 2013 i have a form that im trying to pass an array that can be a diffrent amount off values. the get string is .php?sel%5B%5D=225&sel%5B%5D=227&sel%5B%5D=232 the values need to be stored in a DB and used at a later date in another page to pull the data back so i need to pull it back out so i can loop the sql (select from database where id = 'array'). the code im trying to use to use the data is (just want to get the data atm) echo 'Hello ' . htmlspecialchars($_GET["sel"]) . '!' but i get an error htmlspecialchars() expects parameter 1 to be string. ive never had to work with an array this way and im pulling my hair out thanks Quote Link to comment https://forums.phpfreaks.com/topic/273360-post-or-get-arrays/ Share on other sites More sharing options...
Jessica Posted January 19, 2013 Share Posted January 19, 2013 You need to fix the original link so it's sel[] not sel%5B%5D Then you can use $_GET['sel'] and see the array. Quote Link to comment https://forums.phpfreaks.com/topic/273360-post-or-get-arrays/#findComment-1406948 Share on other sites More sharing options...
Barand Posted January 19, 2013 Share Posted January 19, 2013 Jessica, what he's getting is "sel[]", in its urlencoded form, being passed as an array in the querystring echo urlencode('sel[]'); // --> sel%5B%5D Hyster, $_GET['sel'] is an array, not a string Quote Link to comment https://forums.phpfreaks.com/topic/273360-post-or-get-arrays/#findComment-1406952 Share on other sites More sharing options...
hyster Posted January 19, 2013 Author Share Posted January 19, 2013 from what ive read i need to pass the array from the form as ( name="sel[]" ) which results in .php?sel%5B%5D=225&sel%5B%5D=227&sel%5B%5D=232 if i remove the [] i get .php?sel=225&sel=227&sel=232 and can only get the last entry. from what i understand the %5B%5D represents the [] in the url. ive removed most of the php and left the java out as this part works ok. <FORM onsubmit="placeInHidden('.', 'sel3', 'hide2');" method="get" action="insert_tanks.php"><SELECT id="sel3" multiple="multiple" size="5"> <?php ?> <option value="<?php echo $row['list']; ?>"><?php echo $row['tier']." - ".$row['name']; ?></option> </SELECT><INPUT id="hide2" name="hide2Name" type="hidden"><BR></FORM></TD> <TD vAlign="middle" align="center"> <FORM><INPUT onclick="moveOptions(document.getElementById('sel3'), document.getElementById('sel4'));" value="-->" type="button"><BR><INPUT onclick="moveOptions(document.getElementById('sel4'), document.getElementById('sel3'));" value="<--" type="button"></FORM></TD> <TD> <FORM onsubmit="selectAllOptions('sel4');" method="get" action="insert_tank.php"> Auto-select<BR><SELECT id="sel4" multiple="multiple" size="5" name="sel"></SELECT><BR><INPUT value="Submit" type="submit"></FORM> Quote Link to comment https://forums.phpfreaks.com/topic/273360-post-or-get-arrays/#findComment-1406953 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.