Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem with to select multiple items

    hi

    i wrote a code to select multiple items in a drop down list.And i store all the items in my database.But in that i select multiple items and submit that items last item only stored.Please tell that what's the mistake in my code.

    PHP Code:

    <td><select name="imagelist" id="imagelist" multiple="multiple">
      <?
      
    while($row=mysql_fetch_array($result))
    {
    $i=1;
    $urlname=$row['urlname'];
    ?>

      <option value="<?=$urlname?>"><?=$ext=strrchr($urlname,'/');?></option>
      
      <?
      
    }
      
    ?>
      </select>
    And i store these items in a database with a name $_POST['imagelist'].

    Anybody plz tell that whats the mistake in my code.plz help me.

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,300
    Thanks
    4
    Thanked 203 Times in 200 Posts
    Change
    Code:
    <td><select name="imagelist" id="imagelist" multiple="multiple">
    to
    Code:
    <td><select name="imagelist[]" id="imagelist" multiple="multiple">
    and you should get the options selected back to PHP in an array named imagelist. You will of course have to get the POST values into your variable using:
    Code:
    $imagelist = $_POST['imagelist'];
    print_r($imagelist);  // show the values that were selected
    Dave .... HostMonster for all of your hosting needs

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by djm0219 View Post
    Change
    Code:
    <td><select name="imagelist" id="imagelist" multiple="multiple">
    to
    Code:
    <td><select name="imagelist[]" id="imagelist" multiple="multiple">
    and you should get the options selected back to PHP in an array named imagelist. You will of course have to get the POST values into your variable using:
    Code:
    $imagelist = $_POST['imagelist'];
    print_r($imagelist);  // show the values that were selected
    And also i want to store all the items in $imagelist in my database.How i store like that?plz tell that

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,300
    Thanks
    4
    Thanked 203 Times in 200 Posts
    Quote Originally Posted by swethak View Post
    And also i want to store all the items in $imagelist in my database.How i store like that?plz tell that
    Depends on the table being used and what columns you have defined.
    Dave .... HostMonster for all of your hosting needs

  • #5
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by swethak View Post
    And also i want to store all the items in $imagelist in my database.How i store like that?plz tell that
    Well, $imagelist = $_POST['imagelist']; will put all the items into an array in the $imagelist variable. Then, you can do a foreach() on $imagelist and insert them in your database or whatever you need to do:

    PHP Code:
    foreach ($imagelist as $key => $value) {
       
    $url mysql_real_escape_string($value);
       
    $insert mysql_query("INSERT INTO images SET url = '$url'");

    This is pretty basic PHP. I would encourage you to read up on the basics of PHP.

    http://www.w3schools.com/PHP/DEfaULT.asP
    http://www.tizag.com/phpT/


  •  

    Posting Permissions

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