Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General »

ayuda please

Estas en el tema de ayuda please en el foro de Bases de Datos General en Foros del Web. hola a todos los duros bueno amigos pasa ke estoy empezando en este cuento de la programacion en php y me gustaria ingresar datos por ...
  #1 (permalink)  
Antiguo 14/10/2009, 19:07
 
Fecha de Ingreso: octubre-2009
Mensajes: 4
Antigüedad: 14 años, 6 meses
Puntos: 0
De acuerdo ayuda please

hola a todos los duros

bueno amigos pasa ke estoy empezando en este cuento de la programacion en php y me gustaria ingresar datos por medio de una pagina web y tengo 2 tablas en una base de datos una llamada estudiantes donde tengo lo siguientes campos (docuemnto, nombre, apellido, telefono, id_colegio) y otra tabla colegios con los siguientes campos (id_colegio, nombre colegio, telefono); lo ke kiero es hacer una pagina php mediante dreamweaver ke el usuario entre y digite los datos (documento, nombre, apellido, telefono) en textbox y en un lista/menu ke el usuario escoja el nombre del colegio y ya habiendo escojido el colegio me esoja el id_colegio y me lo ingrese al id_colegio de la tabla estudiantes como hago esto por dreamweaver mediante codigo

les agradezco la ayuda
aki el codigo
<?php require_once('Connections/conexion9.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 estudiantes (documento, nombre, apellidos, cod_colegio, telefono, direccion, id_carrera) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['documento'], "int"),
GetSQLValueString($_POST['nombre'], "text"),
GetSQLValueString($_POST['apellidos'], "text"),
GetSQLValueString($_POST['cod_colegio'], "int"),
GetSQLValueString($_POST['telefono'], "int"),
GetSQLValueString($_POST['direccion'], "text"),
GetSQLValueString($_POST['id_carrera'], "int"));

mysql_select_db($database_conexion9, $conexion9);
$Result1 = mysql_query($insertSQL, $conexion9) or die(mysql_error());

$insertGoTo = "lis_estudiantes.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
$insertSQL = sprintf("INSERT INTO estudiantes (documento, nombre, apellidos, cod_colegio, telefono, direccion, id_carrera) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['documento'], "int"),
GetSQLValueString($_POST['nombre'], "text"),
GetSQLValueString($_POST['apellidos'], "text"),
GetSQLValueString($_POST['cod_colegio'], "int"),
GetSQLValueString($_POST['telefono'], "int"),
GetSQLValueString($_POST['direccion'], "text"),
GetSQLValueString($_POST['id_carrera'], "int"));

mysql_select_db($database_conexion9, $conexion9);
$Result1 = mysql_query($insertSQL, $conexion9) or die(mysql_error());

$insertGoTo = "lis_estudiantes.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_conexion9, $conexion9);
$query_Recordset1 = "SELECT * FROM estudiantes";
$Recordset1 = mysql_query($query_Recordset1, $conexion9) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

mysql_select_db($database_conexion9, $conexion9);
$query_Recordset2 = "SELECT * FROM colegios";
$Recordset2 = mysql_query($query_Recordset2, $conexion9) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);

mysql_select_db($database_conexion9, $conexion9);
$query_Recordset3 = "SELECT * FROM programas";
$Recordset3 = mysql_query($query_Recordset3, $conexion9) or die(mysql_error());
$row_Recordset3 = mysql_fetch_assoc($Recordset3);
$totalRows_Recordset3 = mysql_num_rows($Recordset3);
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<div align="center">
<h1>Ingreso de estudiantes
</h1>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>

<p>&nbsp;</p>

<form method="post" name="form2" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Documento:</td>
<td><input type="text" name="documento" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Nombre:</td>
<td><input type="text" name="nombre" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Apellidos:</td>
<td><input type="text" name="apellidos" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Telefono:</td>
<td><input type="text" name="telefono" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Direccion:</td>
<td><input type="text" name="direccion" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Colegio</td>
<td><select name="select">
<?php
do {
?>
<option value="<?php echo $row_Recordset2['cod_colegio']?>"<?php if (!(strcmp($row_Recordset2['cod_colegio'], $row_Recordset2['cod_colegio']))) {echo "selected=\"selected\"";} ?>><?php echo $row_Recordset2['nombre_colegio']?></option>
<?php
} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
$rows = mysql_num_rows($Recordset2);
if($rows > 0) {
mysql_data_seek($Recordset2, 0);
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
}
?>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Programa</td>
<td><select name="select2">
<?php
do {
?>
<option value="<?php echo $row_Recordset3['id_programa']?>"<?php if (!(strcmp($row_Recordset3['id_programa'], $row_Recordset3['id_programa']))) {echo "selected=\"selected\"";} ?>><?php echo $row_Recordset3['programa']?></option>
<?php
} while ($row_Recordset3 = mysql_fetch_assoc($Recordset3));
$rows = mysql_num_rows($Recordset3);
if($rows > 0) {
mysql_data_seek($Recordset3, 0);
$row_Recordset3 = mysql_fetch_assoc($Recordset3);
}
?>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><input type="submit" value="Insertar registro"></td>
</tr>
</table>
<input type="hidden" name="cod_colegio" value="<?php echo $row_Recordset2['cod_colegio']; ?>">
<input type="hidden" name="id_carrera" value="<?php echo $row_Recordset3['id_programa']; ?>">
<input type="hidden" name="MM_insert" value="form2">
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Recordset1);

mysql_free_result($Recordset2);

mysql_free_result($Recordset3);
?>

Última edición por chelo989; 14/10/2009 a las 20:20
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:21.