I have 2 tables called 'currency' and 'content' currency = cur_id, cur_country, cur_code example= 1,USA,USD content = id, name, email, country, currency Then I have a form with: name, email, country on submit insert into 'content' - $name, $email, $country, $currency I need a query to automatically insert row 'cur_code' from table currency into row 'currency' of table content according to the country selected I hope I explained this well enough.
In the form where you are getting the input, populate that form from the table "currency", so that the value should contain country and curreny. For example: <select name="select" id="select"> <option value="USA-USD">USA</option> <option value="UK-GBP">UK</option> </select> HTML: For example when the user selects USA, you will get the value "USA-USD". Using split() function, you will get an array in which the 1st element of array will have country name and the 2nd element will have currency. Now you can insert the currency code in the content table
Thanx, i'm getting somewhere now... If I did this... <?php $sql = "SELECT * FROM currency order by cur_country ASC"; $result = mysql_query($sql); while ($record = mysql_fetch_object($result)) { ?> <option value="<?php echo "$record->cur_country";?>-<?php echo "$record->cur_code";?>"><?php echo "$record->cur_country";?></option> <?php } ?> <option value="Other">Other</option> </select> How would I then split it?
this works in MS SQL, how to make it work in MySql INSERT INTO content (country, currency) VALUES ('$country', (SELECT cur_code FROM cur_country WHERE cur_country = '$country'))
I got it thanx <?php $country = "$record->country"; list($country, $currency) = split('[/.-]', $country); echo "Country: $country<br />\n"; ?>