1 Replies - 661 Views - Last Post: 03 June 2008 - 09:33 PM Rate Topic: -----

#1 hari555  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-May 08

to add mutiple option values in db

Posted 03 June 2008 - 04:45 AM

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.

 <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.

<?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:

Is This A Good Question/Topic? 0
  • +

Replies To: to add mutiple option values in db

#2 no2pencil  Icon User is offline

  • Dic Head
  • member icon

Reputation: 5159
  • View blog
  • Posts: 26,768
  • Joined: 10-May 07

Re: to add mutiple option values in db

Posted 03 June 2008 - 09:33 PM

Try incrimenting your $compRow array, instead of just indexing the 1st value.
 <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++;
  }
?>


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1