Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/09/2011, 13:41
martin__90
 
Fecha de Ingreso: septiembre-2011
Mensajes: 1
Antigüedad: 12 años, 7 meses
Puntos: 1
Pregunta Ayudacon combobox vinculado en formulario para cargar a base de datos

Que tal queria pedirles ayuda con este código, tengo todo armado ya lo que me debe faltar es algo muy pequeño o algo que hice mal.
Lo que necesito es que cuando seleccione una provincia en el menu prov salgan las localidades de la misma en el menu loc.

Estuve leyendo mucho y tocando el codigo pero no lo pude lograr, soy novato en este tema y me esta costando mucho descubrir cual es el problema.

Les dejo el código:



<?php require_once('../Connections/gestogestion.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 casas (cod, `desc`, prov, loc, direc, precio, sup, amb, img) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['cod'], "text"),
GetSQLValueString($_POST['desc'], "text"),
GetSQLValueString($_POST['prov'], "text"),
GetSQLValueString($_POST['loc'], "text"),
GetSQLValueString($_POST['direc'], "text"),
GetSQLValueString($_POST['precio'], "double"),
GetSQLValueString($_POST['sup'], "double"),
GetSQLValueString($_POST['amb'], "double"),
GetSQLValueString($_POST['img'], "int"));

mysql_select_db($database_gestogestion, $gestogestion);
$Result1 = mysql_query($insertSQL, $gestogestion) or die(mysql_error());
}

mysql_select_db($database_gestogestion, $gestogestion);
$query_provincias = "SELECT * FROM provincias ORDER BY nombre ASC";
$provincias = mysql_query($query_provincias, $gestogestion) or die(mysql_error());
$row_provincias = mysql_fetch_assoc($provincias);
$totalRows_provincias = mysql_num_rows($provincias);

$colname_localidad = "-1";
if (isset($_POST['prov'])) {
$colname_localidad = (get_magic_quotes_gpc()) ? $_POST['prov'] : addslashes($_POST['prov']);
}
mysql_select_db($database_gestogestion, $gestogestion);
$query_localidad = sprintf("SELECT id, nombre FROM departamentos WHERE provincia_id = 'prov'", GetSQLValueString($colname_localidad, "int"));
$localidad = mysql_query($query_localidad, $gestogestion) or die(mysql_error());
$row_localidad = mysql_fetch_assoc($localidad);
$totalRows_localidad = mysql_num_rows($localidad);
?>
<!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=utf-8" />
<title>Documento sin título</title>
</head>

<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Cod:</td>
<td><input type="text" name="cod" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Desc:</td>
<td><input type="text" name="desc" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Prov:</td>
<td><select name="prov" id="prov" onChange="this.submit()">
<option value="" <?php if (!(strcmp("", $_POST['prov']))) {echo "selected=\"selected\"";} ?>>provincia</option>
<?php
do {
?>
<option value="<?php echo $row_provincias['id']?>"<?php if (!(strcmp($row_provincias['id'], $row_provincias['id']))) {echo "selected=\"selected\"";} ?>><?php echo $row_provincias['nombre']?></option>
<?php
} while ($row_provincias = mysql_fetch_assoc($provincias));
$rows = mysql_num_rows($provincias);
if($rows > 0) {
mysql_data_seek($provincias, 0);
$row_provincias = mysql_fetch_assoc($provincias);
}
?>
</select></td>
</tr>
<tr> </tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Loc:</td>
<td><select name="loc" id="loc">
<option value="" <?php if (!(strcmp("value", $_POST['loc']))) {echo "selected=\"selected\"";} ?>>localidad</option>
<?php
do {
?>
<option value="<?php echo $row_localidad['id']?>"<?php if (!(strcmp($row_localidad['id'], $_POST['loc']))) {echo "selected=\"selected\"";} ?>><?php echo $row_localidad['nombre']?></option>
<?php
} while ($row_localidad = mysql_fetch_assoc($localidad));
$rows = mysql_num_rows($localidad);
if($rows > 0) {
mysql_data_seek($localidad, 0);
$row_localidad = mysql_fetch_assoc($localidad);
}
?>
</select></td>
</tr>
<tr> </tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Direc:</td>
<td><input type="text" name="direc" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Precio:</td>
<td><input type="text" name="precio" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Sup:</td>
<td><input type="text" name="sup" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Amb:</td>
<td><input type="text" name="amb" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Img:</td>
<td><input type="text" name="img" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">&nbsp;</td>
<td><input type="submit" value="Insertar registro" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($provincias);

mysql_free_result($localidad);
?>

Desde ya muchas gracias, espero algún día poder ayudar a otros =)