Whats wrong with this code?
Posted: Sun Jun 16, 2002 8:51 pm
Hi,
This is driving me crazy.
How do I get multiple selected option values from a dropdown list, in a form, to insert into a table? I only seem to be able to get the first selection sent to the database. Or if I make it an array...... i.e.:
<select size="3" name="sport_type[]" multiple>
<option>baseball </option>
<option>football</option>
<option>basketball</option>
<option>soccer </option>
.......I get the just the word Array in the table column. I take this to mean that the multiple selected option values are stored, in the table column, as an array. When I use FOREACH to extract the data from the array, from the database, I still get just the word Array returned! MYSQL_FETCH_ROW does the same thing. What is wrong? Do I have to maybe nest FOREACH statements? I tried but just got an argument error.
How does it work? Actual code below:
FORM THAT SENDS DATA TO MySQL DATABASE....
<select size="3" name="date_day[]" multiple>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
</select>
PHP RESULTS QUERY PAGE....
$query = "SELECT date_day FROM eventpost
$result = mysql_query($query);
while ($dayarray=mysql_fetch_array($result))
{
foreach ($dayarray as $day)
{
echo"<br><b>The days are </b>"."$day";
}
}
THE ACTUAL RESULTS ARE AS FOLLOWS:
The days are Array
I want it to return:
The days are 1
The days are 2
The days are 4 ...etc.
Thanks for any advice.
This is driving me crazy.
How do I get multiple selected option values from a dropdown list, in a form, to insert into a table? I only seem to be able to get the first selection sent to the database. Or if I make it an array...... i.e.:
<select size="3" name="sport_type[]" multiple>
<option>baseball </option>
<option>football</option>
<option>basketball</option>
<option>soccer </option>
.......I get the just the word Array in the table column. I take this to mean that the multiple selected option values are stored, in the table column, as an array. When I use FOREACH to extract the data from the array, from the database, I still get just the word Array returned! MYSQL_FETCH_ROW does the same thing. What is wrong? Do I have to maybe nest FOREACH statements? I tried but just got an argument error.
How does it work? Actual code below:
FORM THAT SENDS DATA TO MySQL DATABASE....
<select size="3" name="date_day[]" multiple>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
</select>
PHP RESULTS QUERY PAGE....
$query = "SELECT date_day FROM eventpost
$result = mysql_query($query);
while ($dayarray=mysql_fetch_array($result))
{
foreach ($dayarray as $day)
{
echo"<br><b>The days are </b>"."$day";
}
}
THE ACTUAL RESULTS ARE AS FOLLOWS:
The days are Array
I want it to return:
The days are 1
The days are 2
The days are 4 ...etc.
Thanks for any advice.