<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>
    </select><br>


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

<?php        
   if (isset($_POST['Submit']))
{      $con=mysqli_connect("localhost","root","","inventory");
$result = mysqli_query($con,"SELECT * FROM color");
    $red=$_POST['red'];
    $royal=$_POST['royal'];
    $black=$_POST['black'];
    $white=$_POST['white'];
    $yellow=$_POST['yellow'];
    $navy=$_POST['navy'];
    $green=$_POST['green'];
    $gray=$_POST['gray'];
    $blue=$_POST['blue'];
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')");


                        }?>

Recommended Answers

All 2 Replies

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

</select>

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

example 2

if(isset($_POST['submit']){
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.

Member Avatar for diafol

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.