Código PHP:
<?php
$conn = mysql_connect("sql5.freesqldatabase.com","sql554951","CONTRASEÑA");
mysql_select_db("sql554951",$conn);
if(isset($_POST["submit"])) {
mysql_query("Update users SET user_name='" . $_POST["user_name"] . "', languages_known='" . implode(",", $_POST["languages_known"]) . "'");
}
$result = mysql_query("SELECT * FROM evaluaciones");
$users= mysql_fetch_array($result);
?>
<html>
<head>
<title>Multiselect in PHP</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<form name="frmUser" method="post" action="insert.php">
<div style="width:500px;">
<table border="0" cellpadding="10" cellspacing="0" width="500" align="center" class="tblSaveForm">
<tr class="tableheader">
<td colspan="2">Evaluaciones masivas</td>
</tr>
<tr>
<tr>
<td><label>Nombre de la Evaluacion</label></td>
<td><input type="text" name="firstname" class="txtField" value="<?php echo $users["user_name"]; ?>"></td>
</tr>
<tr>
<td><label>Competencias</label></td>
<td><select name="lastname" multiple="multiple">
<?php
$users_language = explode(",",$users["languages_known"]);
$languages_result = mysql_query("SELECT * FROM Competencias");
$i=0;
while($languages_stack = mysql_fetch_array($languages_result)) {
if(in_array($languages_stack["lang_name"],$users_language)) $str_flag = "selected";
else $str_flag="";
?>
<option value="<?=$languages_stack["Nombre"];?>" <?php echo $str_flag; ?>>
<?=$languages_stack["Nombre"];?>
</option>
<?php
$i++;
}
?>
</select></td>
</tr>
<td><label>Empleados a evaluar</label></td>
<td>
<select name="Empleado" multiple="multiple">
<?php
$users_language = explode(",",$users["languages_known"]);
$languages_result = mysql_query("SELECT * FROM Empleados");
$i=0;
while($languages_stack = mysql_fetch_array($languages_result)) {
if(in_array($languages_stack["lang_name"],$users_language)) $str_flag = "selected";
else $str_flag="";
?>
<option value="<?=$languages_stack["Nombre"];?>" <?php echo $str_flag; ?>><?=$languages_stack["Nombre"];?></option>
<?php
$i++;
}
?>
</select>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Submit" class="btnSubmit"></td>
</tr>
</table>
</div>
</form>
</body></html>
y el file que inserta la info:
Código PHP:
<html>
<body>
<?php
$con = mysql_connect("sql5.freesqldatabase.com","sql554951","CONTRASEÑA");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sql554951", $con);
$sql="INSERT INTO Masiva (firstname, lastname, Empleado)
VALUES('$_POST[firstname]','$_POST[lastname]','$_POST[Empleado]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
</body>
</html>
Desde ya mil gracias!