how do i insert 3 values into same database field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lisa007
    New Member
    • Apr 2010
    • 29

    #1

    how do i insert 3 values into same database field

    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
    Code:
    $select3 = $_POST['select1 || select2 || select3'];
    
    
    $query="INSERT INTO photos values ('$select3')"; 
    
    
    this is the drop down
    
    [PHP]$select3 = $_POST['select1 && select2 && select3'];
    
    
    
    
    
    $query="INSERT INTO photos values ('$select3')";
    
    
    
    
    
    <select id="in-campu" name="select1">
    
     <option name="hot"  value="default">--Select  Music Type--</option>
    
    <option name="how" value="Concerts">Concerts</option>
    
    <option name="hot" value="Clubs" >Clubs</option>
    
    <option name="hot" value="Festival">Festival</option>
    
    <option name="hot" value="Opera">Opera</option>
    
    
    
    </select>
    
    
    
        <select id="off-campus" class="item" name="select2" style="display: none;">
    
     <option name="hot" value="default"> -- Select Sport Type -- </option>
    
    <option name="hot" value="Formula 1">Formula 1</option>
    
    <option name="hot" value="Footbal">Footbal</option>
    
    <option name="hot" value="Basketball">Basketball</option>
    
    <option name="hot" value="Rugby">Rugby</option>
    
    <option name="hot" value="Cricket">Cricket</option>
    
    </select>
    
    
    
        <select id="one" class="item" name="select3" style="display: none;">
    
    <option name="one" value="default"> -- Select Art & Theatre Type -- </option>
    
    <option name="one" value="Comedy">Comedy</option>
    
    <option name="one"  value=" Drama">Drama</option>
    
    <option name="one" value="Museus">Museus</option>
    
    </select>
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    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:
    [code=php]<?php
    $value = null;
    if(isset($_POST['select1']) && !empty($_POST['select1'])) {
    $value = $_POST['select1'];
    }
    else if(isset($_POST['select2']) && !empty($_POST['select2'])) {
    $value = $_POST['select2'];
    }
    else ( // {
    // A box was not submited.
    echo "Please select something!";
    }

    if($value == null) { // !
    // Insert the value into a database
    }
    ?>[/code]

    Comment

    Working...