By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,695 Members | 1,597 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,695 IT Pros & Developers. It's quick & easy.

how do i insert 3 values into same database field

P: 29
i have 3 drop down which the user can only select one each has they own name like select 1 select 2 and select 3 but i want whichever the user select to go into the same field on the database.. at the moment i named the field select3 but that only store value of the drop down named SELECt3 how do i get if user chose select2 insert the value on same field as if chose select 1 or 3

i tried
Expand|Select|Wrap|Line Numbers
  1. $select3 = $_POST['select1 || select2 || select3'];
  2.  
  3.  
  4. $query="INSERT INTO photos values ('$select3')"; 
  5.  
  6.  
  7. this is the drop down
  8.  
  9. [PHP]$select3 = $_POST['select1 && select2 && select3'];
  10.  
  11.  
  12.  
  13.  
  14.  
  15. $query="INSERT INTO photos values ('$select3')";
  16.  
  17.  
  18.  
  19.  
  20.  
  21. <select id="in-campu" name="select1">
  22.  
  23.  <option name="hot"  value="default">--Select  Music Type--</option>
  24.  
  25. <option name="how" value="Concerts">Concerts</option>
  26.  
  27. <option name="hot" value="Clubs" >Clubs</option>
  28.  
  29. <option name="hot" value="Festival">Festival</option>
  30.  
  31. <option name="hot" value="Opera">Opera</option>
  32.  
  33.  
  34.  
  35. </select>
  36.  
  37.  
  38.  
  39.     <select id="off-campus" class="item" name="select2" style="display: none;">
  40.  
  41.  <option name="hot" value="default"> -- Select Sport Type -- </option>
  42.  
  43. <option name="hot" value="Formula 1">Formula 1</option>
  44.  
  45. <option name="hot" value="Footbal">Footbal</option>
  46.  
  47. <option name="hot" value="Basketball">Basketball</option>
  48.  
  49. <option name="hot" value="Rugby">Rugby</option>
  50.  
  51. <option name="hot" value="Cricket">Cricket</option>
  52.  
  53. </select>
  54.  
  55.  
  56.  
  57.     <select id="one" class="item" name="select3" style="display: none;">
  58.  
  59. <option name="one" value="default"> -- Select Art & Theatre Type -- </option>
  60.  
  61. <option name="one" value="Comedy">Comedy</option>
  62.  
  63. <option name="one"  value=" Drama">Drama</option>
  64.  
  65. <option name="one" value="Museus">Museus</option>
  66.  
  67. </select>
Apr 20 '10 #1
Share this Question
Share on Google+
1 Reply


Atli
Expert 5K+
P: 5,058
Hey.

So, basically, you allow the user to select from only one of the <select> boxes, and you need the value of that box to be inserted into the database?

If so, you would simply have to go through the boxes, one by one, and check if they have a value. Like:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $value = null;
  3. if(isset($_POST['select1']) && !empty($_POST['select1'])) {
  4.     $value = $_POST['select1'];
  5. }
  6. else if(isset($_POST['select2']) && !empty($_POST['select2'])) {
  7.     $value = $_POST['select2'];
  8. }
  9. else ( // {
  10.     // A box was not submited.
  11.     echo "Please select something!";
  12. }
  13.  
  14. if($value == null) { // !
  15.     // Insert the value into a database
  16. }
  17. ?>
Apr 20 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.