Estimados, tengo un formulario, el cual tiene datos en forma de select traidos desde una base de datos, el problema es que al momento de escribir los datos en la nueva base de datos no me guarda los datos que tienen los combobox... todo lo que es texto plano ningun drama...
Código PHP:
<?php require_once('Connections/localhost.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO proyectos (proy, noper, admpro, contacto, region, comuna, direccion, telefono, correo, pert) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString(strtoupper($_POST['proy']), "text"),
GetSQLValueString(strtoupper($_POST['noper']), "text"),
GetSQLValueString(strtoupper($_POST['admpro']), "text"),
GetSQLValueString(strtoupper($_POST['contacto']), "text"),
GetSQLValueString($_POST['region'], "text"),
GetSQLValueString($_POST['comuna'], "text"),
GetSQLValueString(strtoupper($_POST['direccion']), "text"),
GetSQLValueString($_POST['telefono'], "text"),
GetSQLValueString($_POST['correo'], "text"),
GetSQLValueString(strtoupper($_POST['pert']), "text"));
mysql_select_db($database_localhost, $localhost);
$Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error());
}
mysql_select_db($database_localhost, $localhost);
$query_pert = "SELECT * FROM tippro";
$pert = mysql_query($query_pert, $localhost) or die(mysql_error());
$row_pert = mysql_fetch_assoc($pert);
$totalRows_pert = mysql_num_rows($pert);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<style type="text/css">
<!--
.Estilo5 {font-family: Arial; font-size: 12; }
.Estilo6 {font-size: 12}
-->
</style>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="Estilo5">Nombre del Proyecto</span>:</td>
<td><input type="text" name="proy" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="Estilo5">Número de Operación </span>:</td>
<td><input type="text" name="noper" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="Estilo5">Administrador del Proyecto</span>:</td>
<td><input type="text" name="admpro" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="Estilo5">Nombre del Contacto</span>:</td>
<td><input type="text" name="contacto" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="Estilo5">Región</span>:</td>
<td><input type="text" name="region" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="Estilo5">Comuna</span>:</td>
<td><input type="text" name="comuna" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="Estilo5">Dirección</span>:</td>
<td><input type="text" name="direccion" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="Estilo5">Telélefono</span>:</td>
<td><input type="text" name="telefono" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="Estilo5">Correo</span>:</td>
<td><input type="text" name="correo" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="Estilo5">Pertenece a</span>:</td>
<td><select>
<?php
do {
?>
<option type="text" name="pert" value="<?php echo $row_pert['pert']?>"><?php echo $row_pert['pert']?></option>
<?php
} while ($row_pert = mysql_fetch_assoc($pert));
$rows = mysql_num_rows($pert);
if($rows > 0) {
mysql_data_seek($pert, 0);
$row_pert = mysql_fetch_assoc($pert);
}
?>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insertar registro" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
<script>
<?php
for($z2=1;$z2 < count($regiones);$z2++) {
$filenamemod="opttec/ciudades/".rtrim($regiones[$z2]).".txt";
$textomod=file($filenamemod);
echo 'var comunas_'.$z2.'=new Array("-"';
for($zmod=1;$zmod<count($textomod);$zmod++) {
echo ',"'.rtrim($textomod[$zmod]).'"';
}
echo ')'.chr(13).chr(10);
}
?>
function cambia_region(){
var selregion
selregion = document.f1.selregion[document.f1.selregion.selectedIndex].value
if (selregion != 0) {
//si estaba definido, entonces coloco las opciones de la comuna correspondiente.
//selecciono el array de comuna adecuado
mis_comunas=eval("comunas_" + selregion)
//calculo el numero de comunas
num_comunas = mis_comunas.length
//marco el número de comunas en el select
document.f1.comuna.length = num_comunas
//para cada comuna del array, la introduzco en el select
for(i=1;i < num_comunas;i++){
document.f1.comuna.options[i].value=mis_comunas[i]
document.f1.comuna.options[i].text=mis_comunas[i]
}
}else{
//si no había comuna seleccionada, elimino las comunas del select
document.f1.comuna.length = 1
//coloco un guión en la única opción que he dejado
document.f1.comuna.options[0].value = "-"
document.f1.comuna.options[0].text = "-"
}
//marco como seleccionada la opción primera de comuna
document.f1.comuna.options[0].selected = true
}
</script>
</body>
</html>
<?php
mysql_free_result($pert);
?>
actualmente el codigo solo tiene combobox para el campo "pertenece a", pero luego tendra uno dinamico para la region-comuna...