kcwebz Posted October 7, 2012 Share Posted October 7, 2012 I have created this form. I am trying to capture the values of the drop down lists but am having a hard time trying to do so, and was hoping someone here might be able to help me. They are being declared using a unique identifier of their respective tables from my sql db. each section of product in that form has its own table and own table id which the drop down lists are using. They are declared in the form like this. echo "<td><select name=". $row['goosedown_id'] ."> <option value=''> 0 </option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> </select> </td>"; Once the user hits submit I then try to capture these drop down lists in my orderform.php like so (this is also where I am having trouble) $goosedown_id = ($_POST[$row['goosedown_id']]); //.. /*-------------------First Email--------------------*/ /* Set Email for Redgraves, so they can for-full the order form */ $message = "Your contact form has been submitted by: Order number : $random Name: $yourname E-mail: $email Phone Number: $phonenumber Mobile Number: $mobilenumber Delivery Address : $deliveryaddress Order: ----------------------------------------------------------------- test goosedown_id: $goosedown_id "foreach ($_POST[$row['goosedown_id']] != 0) { "test goosedown_id: $goosedown_id" }" ----------------------------------------------------------------- Comments: $comments End of message "; /* Send the message using mail() function */ mail($myemail, "Order Submitted", $message); As you can see I have made a minor attempt at getting the drop down lists values that are not equal to 0.. but this code is defiantly not working.. but hopefully it serves a purpose to show you waht I am trying to achieve.. any help would be greatly appreciated.. been stuck on this problem all weekend. Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 7, 2012 Share Posted October 7, 2012 You can't have a foreach in a string. This code will generate errors. You have to add to the string within the loop. Quote Link to comment Share on other sites More sharing options...
kcwebz Posted October 7, 2012 Author Share Posted October 7, 2012 I was just trying to show people what I am trying to achieve, I don't really know how to put it into words.. I have tried so much now just to get one of thedrop down lists values to be printed out that I dunno what else to do. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 7, 2012 Share Posted October 7, 2012 If I understand you correctly, it sounds like you should set up the select fields as an array in the form. Then you can loop over that array to get each value. Quote Link to comment Share on other sites More sharing options...
kcwebz Posted October 7, 2012 Author Share Posted October 7, 2012 oh right.. Okay well will go give that a research then... Been stuck on this problem all weekend.. soo close but so far away. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 7, 2012 Share Posted October 7, 2012 (edited) It should be as simple as adding the array name in the name atribute of your select fields. Then each key will be the value of $row['goosedown_id'] echo "<select name=\"array_name_goes_here[{$row['goosedown_id']}]\">\n"; followed by your <option></option> tag sets, etc. Repeat for each select field, then echo '<pre>'; print_r($_POST); echo '</pre>'; to see the structure of the data. You should be easily able to loop over it once you see the structure. Edited October 7, 2012 by Pikachu2000 Quote Link to comment Share on other sites More sharing options...
kcwebz Posted October 7, 2012 Author Share Posted October 7, 2012 Thank you for your response, I am working on understanding your code Im still quite new to PHP so just trying to understand what all the {} do etc. Quote Link to comment Share on other sites More sharing options...
Christian F. Posted October 7, 2012 Share Posted October 7, 2012 If you haven't done so already, you might want to read the PHP manual. If you start on the chapter I linked you to, and at least read everything up to the chapter about Classes, it should explain most of the things you'll need with PHP. The "Function Reference" chapter is also very useful, but that's more of a "when needed" basis. Though, if you want to read through it all, then all the more power to you. Quote Link to comment 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.