<form method="POST">

Color: <select name="Color">
<option> </option>
<option name="red"> Red</option>
<option name="royal"> Royal Blue</option>
<option name="black"> Black</option>
<option name="white"> White</option>
<option name="yellow"> Yellow</option>
<option name="navy"> Navy</option>
<option name="green"> Green</option>
<option name="gray"> Gray</option>
<option name="blue"> Blue</option>

<input type="Submit" name="Submit"value="Save">

   if (isset($_POST['Submit']))
{      $con=mysqli_connect("localhost","root","","inventory");
$result = mysqli_query($con,"SELECT * FROM color");
mysql_query("INSERT INTO `inventory`.`color`(red,royal,black,white,yellow,navy,green,gray,blue)
     VALUES ('$red','$royal','$black','$white','$yellow','$navy','$green','$gray','$blue')");

4 Years
Discussion Span
Last Post by diafol

That will not work.. you will need to set the select multiple property and the name attribute to some array.

for example

<select name="color[]" multiple>
<option value="red">
<!-- add more options here -->


for the php processor, you need to iterate throught the color array(), by using foreach..

example 2

foreach($_POST['color'] as $colors){

    echo $colors.'<br/>';

Just to remind you that I am only using the echo for demonstration. YOu can easily pass the submitted value for your database query.

The above codes shown is for multiple selection of colors. For single color selection, remove the array designator.

Edited by veedeoo: more info. added


What values are you expecting to insert into the DB? From this it looks like you're inserting the literal colour name into, so if you echoed out your sql and if all values were chosen in the 'multiple' select box...

INSERT INTO `inventory`.`color`(red,royal,black,white,yellow,navy,green,gray,blue)
     VALUES ('red','royal','black','white','yellow','navy','green','gray','$blue')

Is that right?
Perhaps if you give an idea of what you're trying to do. What does this data actually mean?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.