Kano Posted March 6, 2007 Share Posted March 6, 2007 Hi there, I have a query regarding <select> name: The script runs through a for loop for each select which gets the qty's from the DB, so the user can only select the maximum thats available in stock. Each select is given a name, which is the record ID from the DB ($wsi_id_arr[$num]). So the first select will be <select name="VB001"> for example. However, the problem i am having is how do I get at this in another script, for example, so far I have: for($ordercnt=0;$ordercnt<$num;$ordercnt++) { if(................... thanks. Quote Link to comment https://forums.phpfreaks.com/topic/41444--/ Share on other sites More sharing options...
monk.e.boy Posted March 6, 2007 Share Posted March 6, 2007 try doing a: <?php print_r( $_POST ); ?> in the second page. This will show all your post variables. You should be able to figure it out from there. monk.e.boy Quote Link to comment https://forums.phpfreaks.com/topic/41444--/#findComment-200792 Share on other sites More sharing options...
Kano Posted March 6, 2007 Author Share Posted March 6, 2007 Hi there, Yes it outputs an array ([VB001] => 6 etc...) How do I get to the key as a variable, because I would like to add all the quantities so that if they are greater than 0 then the user has made a purchase thanks. Quote Link to comment https://forums.phpfreaks.com/topic/41444--/#findComment-200821 Share on other sites More sharing options...
mbtaylor Posted March 6, 2007 Share Posted March 6, 2007 Use a foreach loop to loop through as associative array. You can use $var => $value to look through all the keys. foreach ($_POST as $var => $value) { # loop through post vars and add up anthing that has "VB" in the variable name. if (strstr ($var, "VB")) { $total += $value; } } if ($total > 0) { # user has made a purchase } /* Note if you did $$var = $value you would get the variable $VB0001 etc. */ But then, why would a Select form field be submitting many VBXXXX values surely it would only be 1? If so you would access that with the name attribute of your select field e.g <select name='something'> $something = $_POST['something']; Does that help? Quote Link to comment https://forums.phpfreaks.com/topic/41444--/#findComment-200827 Share on other sites More sharing options...
Kano Posted March 6, 2007 Author Share Posted March 6, 2007 Yes thanks man, The form is a list with select at end to select qty's, it is a simple form for our furniture wholesale customers so they can select everything they want on one form for a container, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/41444--/#findComment-200829 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.