Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2012
    Posts
    8

    Unanswered: Storing multiple values from a dropdown list

    Hello

    How can I store multiple selected values (from a dropdown list) in mysql database?


    PHP Code:
    <form method="post" action="storedetails.php">
        
    Research Interest:<br/>
        <
    select multiple="yes" size="6" name="interest[]">
        <
    option id="webt" value="webt">Advanced Web Tech1nologies</option>
        <
    option id="mobhum" value="mobhum">Mobile and Humanoid Robots</option>
        <
    option id="java" value="java">Java Programming</option>
        <
    option id="graphics" value="graphics">Computer Graphics/Animation</option>
        <
    option id="software" value="software">Software Development</option>
        <
    option id="systems" value="systems">Computer Systems</option>
        <
    option id="gamedev" value="gamedev">Game Development</option>
        <
    option id="infodata" value="infodata">Information Databases</option>
        <
    option id="hci" value="hci">Human Computer Interaction</option>
        <
    option id="mobprogramming" value="mobprogramming">Mobile Device Programming</option>
        </
    select></br>
    <
    input type="submit" name="submit" value="Register"/>
    </
    div>
    </
    form
    Page: storedetails.php
    PHP Code:
     include 'mysql_connect.php';
      
    session_start();
      include 
    'header.php'

      $???????? = 
    $_POST['???????????'];

     
    $query "...........................";
          
    $result mysql_query($query) or die ("query failed: " mysql_error());
      
      exit();
      }
      
    mysql_close($dbc); 

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    I think you are looking for a while loop in PHP.

  3. #3
    Join Date
    Apr 2012
    Posts
    8
    can you please post a sample code? cause i have no idea how to do it.
    What if someone choose only 3 options, or 5 or 8 or none? I'm kind of confused

  4. #4
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    That's more of a PHP thing. I don't know enough PHP to be able to navigate you through iterating through the individual selected items.

  5. #5
    Join Date
    Apr 2012
    Posts
    8
    Oh ok man fair enough, thanks anyway

  6. #6
    Join Date
    Apr 2012
    Posts
    8
    anyone?
    I think it's something like that:

    Page: storedetails.php
    PHP Code:
     include 'mysql_connect.php';
      
    session_start();
      include 
    'header.php'

      
    $interest $_POST['interest'];
      for(
    $i 0$i count($interest); $i++){
        
    $query "INSERT INTO book(research_interest) VALUES('$interest[$i]')";
         
    $result mysql_query($query) or die ("query failed: " mysql_error());
      }

      exit();
      }
      
    mysql_close($dbc); 

    [PHP]
    PHP Code:
    <form method="post" action="storedetails.php">
        
    Research Interest:<br/>
        <
    select multiple="multiple" name="interest[]">
        <
    option id="webt" value="webt">Advanced Web Tech1nologies</option>
        <
    option id="mobhum" value="mobhum">Mobile and Humanoid Robots</option>
        <
    option id="java" value="java">Java Programming</option>
        <
    option id="graphics" value="graphics">Computer Graphics/Animation</option>
        <
    option id="software" value="software">Software Development</option>
        <
    option id="systems" value="systems">Computer Systems</option>
        <
    option id="gamedev" value="gamedev">Game Development</option>
        <
    option id="infodata" value="infodata">Information Databases</option>
        <
    option id="hci" value="hci">Human Computer Interaction</option>
        <
    option id="mobprogramming" value="mobprogramming">Mobile Device Programming</option>
        </
    select></br>
    <
    input type="submit" name="submit" value="Register"/>
    </
    div>
    </
    form
    Last edited by shieldcy; 04-11-12 at 18:31.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •