Ver Mensaje Individual
  #6 (permalink)  
Antiguo 20/12/2011, 15:14
chumy_
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: formulario no guarda datos desde mysql

ahora tengo otra consulta, me guarda el valor de region_id y no de region_nombre y la comuna directamente no la guarda

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"] == "f1")) {
  
$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(strtoupper($_POST['region']), "text"),
                       
GetSQLValueString(strtoupper($_POST['comuna']), "text"),
                       
GetSQLValueString(strtoupper($_POST['direccion']), "text"),
                       
GetSQLValueString($_POST['telefono'], "text"),
                       
GetSQLValueString($_POST['correo'], "text"),
                       
GetSQLValueString($_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_Recordset1 "SELECT * FROM proyectos";
$Recordset1 mysql_query($query_Recordset1$localhost) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);

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);

$con mysql_connect("localhost","root","")
     or die (
"Error al conectar a la base de datos.");
mysql_select_db("optchile"$con)
     or die (
"Error al conectar a la base de datos.");
?>
<html>

<head>
<script type="text/javascript" language="javascript" src="js/funciones.js"></script>
<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>

<?php
$proy 
$_POST['proy'];
$noper $_POST['noper'];
$admpro $_POST['admpro'];
$contacto $_POST['contacto'];
$region $_POST['region'];
$comuna $_POST['comuna'];
$direccion $_POST['direccion'];
$telefono $_POST['telefono'];
$correo $_POST['correo'];
$pertenece $_POST['pertenece'];
?>


<body>


<form action="<?php echo $editFormAction?>" method="POST" name="f1" target="_self" id="f1">


<table width="72%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
      <table width="102%"  align="center" border="0" cellspacing="4" cellpadding="0">
      <tr>
        <td width="49%" ><div align="right"><span class="Estilo5">Nombre del Proyecto : </span></div></td>
        <td width="51%"><span class="Estilo5">
          <input name="proy" type="text" id="proy" size="50" maxlength="80" />
        </span></td>
      </tr>
         <tr>
        <td width="49%"><div align="right"><span class="Estilo5">N&uacute;mero de Operaci&oacute;n : </span></div></td>
        <td width="51%"><span class="Estilo6">
          <input name="noper" type="text" id="noper" size="6" maxlength="6"/>
          </span></td>
      </tr>
          <td><div align="right"><span class="Estilo5">Administrador del Proyecto : </span></div></td>
        <td><span class="Estilo6">
          <input name="admpro" type="text" id="admpro" size="50" maxlength="80"/>
          </span></td>
      </tr>
      <tr>
        <td><div align="right"><span class="Estilo5">Nombre del Contacto : </span></div></td>
        <td><span class="Estilo6">
          <input name="contacto" type="text" id="contacto" size="50" maxlength="80"/>
        </span></td>
      </tr>
      <tr>
        <td><div align="right"><span class="Estilo5">Región : </span></div></td>
<?php
$sql
="select region_id,region_nombre from regiones order by region_id asc";
$res=mysql_query($sql,$con);
?>       
<td>
<select name="region" onChange="from(document.f1.region.value,'comuna','comuna.php')">
<option value="0">Seleccione la regi&oacute;n</option>

<?php
while ($region=mysql_fetch_array($res))
{
?>
<option value="<?php echo $region["region_id"];?>"><?php echo $region["region_nombre"];?></option>
<?php
}
?>

</select> 
</td>
          </tr>            
         <tr>
            <td><div align="right"><span class="Estilo5">Comuna : </span></div></td>
<td>
<div id="comuna">
<select name="comuna">
<option value="0">Seleccione la comuna</option>
</select>
</div>
</td>
         </tr>
                 
      <tr>
        <td><div align="right"><span class="Estilo5">Direcci&oacute;n : </span></div></td>
        <td><span class="Estilo6">
          <input name="direccion" type="text" id="direccion" size="50" maxlength="200"/>
          </span></td>
      </tr>
      <tr>
        <td><div align="right"><span class="Estilo5">Tel&eacute;lefono : </span></div></td>
        <td><span class="Estilo6">
          <input name="telefono" type="text" id="telefono" size="50" maxlength="50"/>
          </span></td>
      </tr>
      <tr>
        <td width="49%"><div align="right"><span class="Estilo5">Correo : </span></div></td>
        <td width="51%"><span class="Estilo6">
          <input name="correo" type="text" id="correo" size="50" maxlength="50"/>
          </span></td>
      </tr>
      <tr>
        <td height="40"><div align="right"><span class="Estilo5">Pertenece a : </span></div></td>
        <td>
        <select name="pert">
          <option value="" <?php if (!(strcmp(""$row_pert['pert']))) {echo "selected=\"selected\"";} ?>>Seleccionar</option>
          <?php
do {  
?>
          <option value="<?php echo $row_pert['pert']?>"<?php if (!(strcmp($row_pert['pert'], $row_pert['pert']))) {echo "selected=\"selected\"";} ?>><?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($pert0);
      
$row_pert mysql_fetch_assoc($pert);
  }
?>
        </select>
        </td>
      </tr>
      <tr>
        <td width="49%"><div align="right"></div></td>
        <td width="51%"><label>
          <input name="CREAR PROYECTO" type="submit" id="CREAR PROYECTO" onClick="MM_validateForm('nompro','','R','numope','','R','admpro','','R','nomcon','','R','direc','','R','telef','','R','correo','','RisEmail');return document.MM_returnValue" value="CREAR PROYECTO" />
          </label>
        <BR /></td>
      </tr>
    </table>
  
    </td>
     </tr>
</table></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
  </tr>
</table>
<input type="hidden" name="MM_insert" value="f1">
</form>
<p>&nbsp;</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
($Recordset1);

mysql_free_result($pert);
?>