bickyz Posted May 31, 2013 Share Posted May 31, 2013 Hi, I have a mysql table with following fieldsid – intcompany – varchar(50)cost – decimal(5,2) Updated - datetime Example of data:101 company1 120.10 2013-05-22 10:21:19102 company2 121.20 2013-05-22 11:11:29103 company3 120.15 2013-05-23 12:44:10104 company4 124.25 2013-05-23 13:26:49 Following is the text field code for cost: Cost: <input type="text" name="txtcost"><br /> How will my php code be if I want to insert Pound and Pence from two form field to one mysql field like this or if there is better method please advice. <select name="pound"> <option value="0" selected="selected">Pound:</option> <option value="120">120</option> <option value="121">121</option> <option value="122">122</option> <option value="123">123</option> <option value="124">124</option> <option value="125">125</option> </select> <select name="pence"> <option value="0" selected="selected">Pence:</option> <option value="00">00</option> <option value="10">10</option> <option value="15">15</option> <option value="20">20</option> <option value="25">25</option> <option value="30">30</option> </select> Your help will be much appreciated, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/278639-insert-value-from-two-dropdown-list-to-same-mysql-field/ Share on other sites More sharing options...
davidannis Posted May 31, 2013 Share Posted May 31, 2013 (edited) You can concatenate the two fields: $cost=$_POST['pounds'].'.'.$_POST['pence]; Edited May 31, 2013 by davidannis Quote Link to comment https://forums.phpfreaks.com/topic/278639-insert-value-from-two-dropdown-list-to-same-mysql-field/#findComment-1433420 Share on other sites More sharing options...
Jessica Posted May 31, 2013 Share Posted May 31, 2013 (edited) Honestly, it's probably easier for the users if you just let them type in the value. In American we use dollars and cents, but rather than having one drop down for dollars and another for cents, almost anywhere you'd need to enter in a monetary value, you'd simply enter: $dd.dd in a text field. (where d=digit). It gets a little more complicated to parse it when you get to larger values where people add the thousands separator, but there are PHP functions to help with that (and you should have your locale settings set to the right one.) Your field won't allow anything over 999.99 so you're fine. Edited May 31, 2013 by Jessica Quote Link to comment https://forums.phpfreaks.com/topic/278639-insert-value-from-two-dropdown-list-to-same-mysql-field/#findComment-1433421 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.