how do i insert 3 values into same database field

Discussion in 'PHP' started by macaela, Apr 20, 2010.

  1. #1
    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
    $select3 = $_POST['select1 || select2 || select3'];
    
    
    $query="INSERT INTO photos values ('$select3')"; 
    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> 
    PHP:
     
    macaela, Apr 20, 2010 IP
  2. shmeeg

    shmeeg Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    doesn't || denote "or"?
     
    shmeeg, Apr 20, 2010 IP
  3. macaela

    macaela Active Member

    Messages:
    181
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    yeah i tried is if post3 or post 2 or post 1
     
    macaela, Apr 20, 2010 IP
  4. s.ham

    s.ham Member

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    It is totally against database normalization. Please consider redesigning your table with every row for a value.
     
    s.ham, Apr 21, 2010 IP
  5. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #5
    You could serialize your 'select' data before storing it, which will give your a storable representation of the data.

    E.G if your post data is;

    Array
    (
        [select1] => default
        [select2] => default
        [select3] => Comedy
    )
    Code (markup):
    <?php
    # NOTE: YOU SHOULD VALIDATE THIS DATA BUT JUST AS AN EXAMPLE
    $details['select1']=$_POST['select1'];
    $details['select2']=$_POST['select2'];
    $details['select3']=$_POST['select3'];
    
    $result = serialize($details);
    
    print $result;
    ?>
    PHP:
    OUTPUT:a:3:{s:7:"select1";s:7:"default";s:7:"select2";s:7:"default";s:7:"select3";s:6:"Comedy";}

    When you retrieve it from the database, just unserialize it.


    
    <?php
    # Select from your database ......
    $selected = unserialize($result);
    print_r($selected);
    PHP:
    ?>[/PHP]

    OUTPUT:array
    (
    [select1] => default
    [select2] => default
    [select3] => Comedy
    )
     
    lukeg32, Apr 21, 2010 IP