jasontallon Posted March 14, 2008 Share Posted March 14, 2008 Hi Any help appreciated. I am new to PHP & MYSQL, I am looking for the following code or advice as to where i could find info re creating same. A drop down menu and input box where when the user selects an option and enters a number in a text area the value is sent to a DB table/field. Example: Drop down menu with 5 options - phone 1, phone 2, etc when user selects phone 2 they then enter a number in an input box and hits submit the number posts to the phone2 field in the table, or user selects phone 3 enters a number in a text field and the number is posted to the phone3 field in the database table. Thanks for any help Jason Quote Link to comment Share on other sites More sharing options...
haku Posted March 14, 2008 Share Posted March 14, 2008 $number = $_POST['drop_down_menu']; $phone = $_POST['phone_number']; $query = "UPDATE phone_numbers SET phone_number{$number}='{$phone}' WHERE something='something'"; Quote Link to comment Share on other sites More sharing options...
ricerocket Posted March 14, 2008 Share Posted March 14, 2008 or if the the user will be using it you can have them input their username so when they select the phone/number it's saved to their "profile" or database row.. whatever you want to call it. I've updated haku's version if it suites your needs: <?PHP $username = $_POST['username']; $number = $_POST['drop_down_menu']; $phone = $_POST['phone_number']; $query = "UPDATE phone_numbers SET phone_number{$number}='{$phone}' WHERE users='$username'"; ?> I think thats how it would go... I could make it way more advanced but I'm not quite sure how you need it. Quote Link to comment Share on other sites More sharing options...
jasontallon Posted March 14, 2008 Author Share Posted March 14, 2008 Hi Thanks for the help, Maybe I can explain further. I have a page for inputing user details, name address etc with optional drop down selections i.e chose country, all this works fine, except for the phone numbers, using a single text input box for this works fine for a single number. But as contacts may have multiple pstn phone numbers, I would like to give the agents/users the option to chose from a list/drop down menu phone 1, phone 2, phone 3 etc then in a text input box beside this be able to type the number. If they for example chose phone 2 the number will get sent to the phone 2 field in the contacts table. I can do this with multiple text input boxs but it seems better done as above. This is what I have Phone Number: <select> <option>Phone 1</option> <option>Phone 2</option> <option>Phone 3</option> <option>Phone 4</option> <option>Phone 5</option> </select> <input name="phone" type="text" value="<?php echo $phone; ?>"> So from the selection whatever is typed in the input box will goto the Phone1 field if chosen from the drop down in the contacts table. Jason Quote Link to comment Share on other sites More sharing options...
haku Posted March 15, 2008 Share Posted March 15, 2008 I understood the first time. The code I gave you is for that. Replace "drop_down_list" with the name of your select element, and replace "phone_number" with "phone" (now that I can see that this is the name of your text input). 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.