I am new around here. I started learning php over a week ago. Sorry bout the noobness. Alright, I am working on a classified ad form. I have two fields that are multiple SELECT and therefore I need to use an array for them. I need a function to get all of the POST_data from those into the corresponding field in the database. I've been looking for over 5 hours for a good working answer to my question. I've tried a few different codes, but they either display the last selection or they show "Array" followed by the first selection.
Here is a sample of the form code for these two items...
<select name="horse_disciplines[]" size="4" multiple="multiple" style="width:180px">
<option value="N/A">-- N/A --</option>
<option value="Barrel Racing">Barrel Racing</option>
<option value="Barrel Racing (Prospect)">Barrel Racing (Prospect)</option>
<option value="Beginner Family">Beginner/Family</option>
<option value="Breeding">Breeding</option>
<option value="Breeding (Prospect)">Breeding (Prospect)</option>
<option value="Broodmare">Broodmare</option>
<option value="Broodmare (Prospect)">Broodmare (Prospect)</option>
etc......
<select name="horse_attributes[]" size="4" multiple="multiple" style="width:180px">
<option value="N/A">-- N/A --</option>
<option value="Breed Assn Futurity Winner">Breed Assn Futurity Winner</option>
<option value="Breed Assn National Champ">Breed Assn National Champ</option>
etc..........
Now for some current php...
//define variables//
$horse_name = $_POST['horse_name'];
$horse_breed =$_POST['horse_breed'];
$horse_disciplines = $_POST["horse_disciplines"];
if (is_array($horse_disciplines)) {
for ($i=0; $i<count($horse_disciplines); $i++) {
$horse_disciplines .= $horse_disciplines[$i].",";
}
$horse_disciplines = substr ($horse_disciplines, 0, strlen ($horse_disciplines)-2);
} else {
$horse_disciplines = "";
}
$horse_attributes = $_POST["horse_attributes"];
if (is_array($horse_attributes)) {
for ($i=0; $i<count($horse_attributes); $i++) {
$horse_attributes .= $horse_attributes[$i].",";
}
$horse_attributes = substr ($horse_attributes, 0, strlen ($horse_attributes)-2);
} else {
$horse_attributes = "";
}
//connect to database//
$db = mysql_connect("localhost", "root","");
mysql_select_db("horse_ads",$db);
//prepare the INSERT query//
$sql = "INSERT INTO text (horse_name, horse_breed, horse_disciplines, horse_attributes,etc....)
VALUES ('$horse_name','$horse_breed','$horse_disciplines','$horse_attributes',etc.....)";
$result = mysql_query($sql);
//end INSERT info to database//
With the current code used to define those multiple SELECT variables I get ArrayBarrel Racing (Prospect (<-note missing parentheses and other selected items)for the horse_disciplines. I get ArrayN/ (<-note the missing A after / for N/A) for horse_attributes. That's what shows up in the corresponding table field.
I need to know how to correctly define my variables for horse_disciplines and horse_attributes with the POST data.
I also need to know if I need to change anything in the VALUES() or if I need to add anything to that section.
I'd like all selected values in one array to be entered into its corresponding table field with commas in between.
I have the single SELECT functions working in my form, but it's just the multiple ones that are giving me trouble.
ANY help would be GREATLY appreciated!