samoht Posted April 2, 2011 Share Posted April 2, 2011 hello all, I have an array value in my post array ($_POST['check0'] ) that I am trying to break up into php variables. For some reason if I do this: $var1 = $_POST['check0'][0]; all I get is the first letter of the string from the first value of the array? Quote Link to comment https://forums.phpfreaks.com/topic/232497-get-array-value-for-variable/ Share on other sites More sharing options...
Jnerocorp Posted April 2, 2011 Share Posted April 2, 2011 can u post more of your code? whats in the array and other processes that have to do with the array? Quote Link to comment https://forums.phpfreaks.com/topic/232497-get-array-value-for-variable/#findComment-1195880 Share on other sites More sharing options...
KevinM1 Posted April 2, 2011 Share Posted April 2, 2011 If check0 is supposed to represent an array of values, you most likely have to put its name as check0[] in your HTML form. That will tell PHP to treat it as an array on the back end. Quote Link to comment https://forums.phpfreaks.com/topic/232497-get-array-value-for-variable/#findComment-1195885 Share on other sites More sharing options...
samoht Posted April 2, 2011 Author Share Posted April 2, 2011 Thanks for the responses, I do have checko0[] in the HTML - that is why the post value is an array right? The issue is the retrieval of the array values into separate variables. I'm not sure I want to store the values in an array in the db (using serialize) - and since my form asks the end user to select only 2 of 5 options I thought I could save the returned values in separate fields like: looking_for_1; looking_for_2 here is some more of my code: HTML: <tr> <td align="right" width="17%"><label class="cf_label" style="width: 150px;">What are you looking for in XXX (select top two)</label></td> <td align="left" width="27%"><div class="float_left"> <input value="Universal image viewer for my images" title="" class="radio" id="check00" name="check0[]" type="checkbox" /> <label for="check00" class="check_label">Universal image viewer for my images</label> <br /> <input value="A portable image database" title="" class="radio" id="check01" name="check0[]" type="checkbox" /> <label for="check01" class="check_label">A portable image database</label> <br /> <input value="Spine specific measuring tools" title="" class="radio" id="check02" name="check0[]" type="checkbox" /> <label for="check02" class="check_label">Spine specific measuring tools</label> <br /> <input value="Surgical Planning tools" title="" class="radio" id="check03" name="check0[]" type="checkbox" /> <label for="check03" class="check_label">Surgical Planning tools</label> <br /> </div></td> </tr> processing: ... $var1 = $_POST['check0'][0]; $var2 = $_POST['check0'][1]; ... //now try the user info save; $query = ' INSERT INTO `#__vm_user_info` (user_info_id,user_id,user_email,perms,pclear,first_name,last_name,country,speciality,yearsexp,hearabout,keyissue,looking_for_1,looking_for_2,whichsoftware,webex) VALUES("'.$strUserinfoID.'", "'.$smuser.'", "'.$smemail.'", "License Owner", "'.$strPassword.'", "'.$smfname.'", "'.$smlname.'", "'.$country.'", "'.$smspeciality.'", "'.$smyearsexp.'", "'.$smhearabout.'", "'.$smkeyissue.'", "'.$var1.'","'.$var2.'", "'.$smwhichsoftware.'", "'.$smwebex.'" )'; $db->setQuery($query); $db->query(); Quote Link to comment https://forums.phpfreaks.com/topic/232497-get-array-value-for-variable/#findComment-1195892 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.