I have a select multiple where the user can select a number of cities and I'd like for each of the selected cities to have PHP make a database entry. For some reason the foreach doesn't seem to be working (there are no entries, although I select cities!). Any help is appreciated.
The code looks like this:
<form action="xy.php" method="post" id="offer">
<p align="left">Select Cities in which you want to offer the Service<br />
<select name="cities[]" size="10" multiple="MULTIPLE" id="offer">
<option>London</option>
<option>New York</option>
<option>Zurich</option>
<option>Zug</option>
<option>Luzern</option>
<option>Bern</option>
</select>
<input type="submit" value="Post Offer" id="offer"/>
</form>
xy.php:
<?php
$dbcnx=@mysql_connect('localhost','root','');
if (!$dbcnx) {
echo '<p>Unable to connect to the '.'Database server at this time.';
exit();
}
mysql_select_db('itopservice',$dbcnx);
$c[]=$_REQUEST['cities[]'];
foreach ($c as $cityname) {
$sql="INSERT INTO citylink SET
serviceid='$serviceid',
cityid='$cityname'";
if (@mysql_query($sql)) {
echo '<p> Entry had been added to Citylink.'; }
else{echo '<p> Error submission: '.mysql_error().'<BR>';}
}
?>