Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,690 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,314 people online right now. Registration is fast and FREE... Join Now!




to add mutiple option values in db

 
Reply to this topicStart new topic

to add mutiple option values in db, Insert and Select

hari555
post 3 Jun, 2008 - 03:45 AM
Post #1


New D.I.C Head

*
Joined: 26 May, 2008
Posts: 1

hi,
i am trying to display all the values from database 1 in select tag and store the selected options in database2.wen trying this only the first option value selected gets stored in db.other values r not getting stored.plea[size=4]se help in this.

this s my code for displaying the values of options from db.

CODE

<select name="test[]" id="test[]" multiple="true" size=5 class="style7">                                <?php
                                    while ($compRow=mysql_fetch_array($result))
                                       {
                                        echo "<option>{$compRow[0]}</option>\n";                                      
                                        }
                                ?>


tis s the code for storing the selected elemnts in db.

CODE

<?php
$test1=$_POST['test'];
for($i=0;$i<sizeof($test1);$i++)
{
$result=mysql_query("INSERT INTO component(projectid,name)VALUES((select max(projectid) from project),'$test1[i]')")or die("Insert Error: ".mysql_error());
}

[size=7]

** Edit ** code.gif
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 3 Jun, 2008 - 08:33 PM
Post #2


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,354



Thanked 58 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


Try incrimenting your $compRow array, instead of just indexing the 1st value.
CODE

<select name="test[]" id="test[]" multiple="true" size=5 class="style7">                                <?php
  $i=0;
  while ($compRow=mysql_fetch_array($result)) {
    echo "<option>{$compRow[$i]}</option>\n";
        $i++;
  }
?>
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:41AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month