Dear everyone,
For the last couple of weeks I've been absolutely stuck on inserting multiple select array (medewerker_voornaam[]) values from the field voornaam in table medewerker (employee) into the table software as medewerker_voornaam. I don't get any error message but the values are just not inserted into the database. I've searched just about the whole forum but still got no clue. All the other field values are inserted perfectly except the field medewerker_voornaam upon pressing the submit button. What could be the cause? I suspect that there might be something wrong with _POST not sending the array values to $medewerker_voornaam. Please ignore the names given to the field values in the tables or the code itself (Dutch).
Thanks in advance.
Below I've posted the code and created table statements:
Software_License_insertion.php
//in this script employee surname (voornaam) is selected from table employee which are shown correctly in the multiple select field//
<SELECT MULTIPLE NAME='medewerker_voornaam[]' id="medewerker_voornaam" size='5' style="width: 240px;">
<?php
$link = mysql_connect("localhost", "root", "password")
or die("Kon geen verbinding tot stand brengen: " . mysql_error());
mysql_select_db('cmdb', $link) or die ( mysql_error());
$sql = "SELECT `voornaam` FROM `medewerker` ORDER BY `voornaam`";
$result = mysql_query($sql)
or die("<font color=\"#FF0000\">Query fout</FONT>".mysql_error());
while ( $row = mysql_fetch_array($result) )
{
echo '<OPTION value="'.$row['medewerker_voornaam'].'">'.$row['voornaam'].'</OPTION>'."\r\n";
}
?>
</SELECT>
Software_License_insertion_commit.php
//in this script employee surname (medewerker_voornaam) should've been inserted into table software//
<?php
$link = mysql_connect("localhost", "root", "password")
or die("Kon geen verbinding tot stand brengen: " . mysql_error());
mysql_select_db('cmdb', $link) or die ( mysql_error());
$medewerker_voornaam = $_POST["voornaam"];
if (is_array($medewerker_voornaam))
{
for ($i=0; $i<count($medewerker_voornaam); $i++)
{
$medewerker_voornaam .= $medewerker_voornaam[$i].", ";
}
$medewerker_voornaam = substr ($medewerker_voornaam, 0, strlen ($medewerker_voornaam)-2);
}
else
{
$medewerker_voornaam = "";
$query=("INSERT INTO `software` (`registratiecode`, `softwarenaam`, `opmerkingen`, `aankoopdatum`, `vernieuwingsdatum`, `prijs`, `cat_naam`, `medewerker_voornaam`) VALUES ( '".$_POST['registratiecode']."' ,'".$_POST['softwarenaam']."' ,'".$_POST['opmerkingen']."' ,'".$_POST['aankoopdatum']."' ,'".$_POST['vernieuwingsdatum']."' ,'".$_POST['prijs']."' ,'".$_POST['categorienaam']."' ,'".$_POST['$medewerker_voornaam']."' )");
mysql_query($query);
}
mysql_close($link);
?>
create table software (code int(10) not null auto_increment, registratiecode varchar(50),softwarenaam varchar(75), opmerkingen text, aankoopdatum date, vernieuwingsdatum date, prijs float(6,2), cat_nr int(10) not null, categorienaam varchar(50) not null, medewerker_voornaam varchar(25), primary key(code), foreign key(cat_nr) references categorie(categorie_nr) on update cascade on delete no action) type=innodb;
//table software licenses, purchased software licenses
create table gebruikte_software (software_code int(10) not null, medewerker_id int(10) not null, primary key(software_code, medewerker_id), foreign key (software_code) references software(code) on update cascade on delete no action, foreign key (medewerker_id) references medewerker(id) on update cascade on delete no action) type=innodb;
//table used software licenses, purchased software licenses in use by an employee, n-n relationship between table software and table employee
create table medewerker (id int(10) not null auto_increment, voornaam varchar(25), achternaam varchar(25), primary key(id)) type=innodb;
//table employee
create table categorie (categorie_nr int(10) not null auto_increment, categorienaam varchar(50) not null, primary key(categorie_nr)) type=innodb;
// table category software i.e. anti-virus or graphical apps