echoing back an array

This is probably a dumb question but I have a problem with echoing back values that I have selected from a multiple-select dropdown (dynamically populated with values from the database) and from input text fields sharing the same name. The user can either select multiple names from a dropdown of already existing professors or add a new professor to the database or both.

here is my form code: [php]

<?php include "include/mysql.connect.php"; $result=mysql_query("select professor_id, professor from professor order by professor"); echo""; while($row = mysql_fetch_assoc($result)) { echo "$row[professor]"; } ?>
	</select>
	</td>
	<td>
	add more: <input type="text" name="professor[]" id="input" size="20" /> 
	<br />
	add more: <input type="text" name="professor[]" id="input" size="20" /> 
	<br />[/php]

When the form gets processed, I want to echo back all the values inserted.
snippet of my post code[php]
$professor = $_POST[‘professor’];
$professordrop = $_POST[‘professordrop’];
[php]

snippet of my echo code:
[php]
echo ‘Professor(s): ‘.$professordrop.’
’;
echo ‘Professor(newly added) :’ .$professor.’
’;
echo 'Course Number: '.$courseno. ‘
’;
echo 'Semester: '.$semester. ‘
’;
[/php]

I fiddled around with it. When the post code is at the very top, the echo will only echo back the last of the array. I have several foreach statements in between the post and echo codes. Is that messing things up? When I copy and paste the post code so that I ahve a copy before I start the echo, I get the string ‘Array’.

By adding [] to the name of the inputs:

[php]
add more:
add more:
[/php]

PHP is treating them as an array. To echo the values you can do:

[php]
foreach($_POST[‘professor’] as $professor)
{
echo ‘Professor(newly added) :’ .$professor.’
’;
}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service