Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-25-2008, 12:56 PM   PM User | #1
swethak
New Coder

 
Join Date: Jul 2008
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
swethak is an unknown quantity at this point
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.
swethak is offline   Reply With Quote
Old 07-25-2008, 01:07 PM   PM User | #2
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
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
djm0219 is offline   Reply With Quote
Old 07-25-2008, 01:53 PM   PM User | #3
swethak
New Coder

 
Join Date: Jul 2008
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
swethak is an unknown quantity at this point
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
swethak is offline   Reply With Quote
Old 07-25-2008, 02:28 PM   PM User | #4
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
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
djm0219 is offline   Reply With Quote
Old 07-25-2008, 02:33 PM   PM User | #5
JohnDubya
Super Moderator


 
JohnDubya's Avatar
 
Join Date: Nov 2006
Location: Missouri
Posts: 633
Thanks: 12
Thanked 18 Times in 18 Posts
JohnDubya is on a distinguished road
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/
__________________
JDub
http://johnnyzone.com/blog
JohnDubya is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:53 AM.


Advertisement
Log in to turn off these ads.