
mostrar datos de dos tablas con select y registrar en otra la relacion
Publicado por moreira (3 intervenciones) el 21/06/2014 08:38:02
Valora esta pregunta


0
<?php
require'../class/sessions.php';
$objses = new Sessions();
$objses->init();
$user = isset($_SESSION['usuario']) ? $_SESSION['usuario'] : null ;
if($user == ''){
header('Location: http://localhost/sinfa/index.php?error=2');
}
?>
<?php
//realizamos la conexión a la base de datos
$objCon = new Connection();
$objCon->get_connected();
//consultamos el listado de las lineas!!
$tipop="SELECT id_categoria, categoria FROM categorias order by id_categoria";
$result1=mysql_query($tipop);
$tipopu="SELECT * FROM lineas order by linea";
$result2=mysql_query($tipopu);
//$linea=$_POST['linea']; $categoria=$_POST['categoria'];
//$resultx = mysql_query ("select id_categoria from categorias where categoria = '$categoria'" ) or die("Error en la consulta SQL");
//$resulty = mysql_query ("select * from lineas where linea = '$linea'" ) or die("Error en la consulta SQL");
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Modulo de Configuración!!</title>
<link rel="stylesheet" href="css3menu/style.css" type="text/css" /><style type="text/css">._css3m{display:none}</style>
</head>
<body style="background-color:#EBEBEB">
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#333399">
<tr>
<td width="51%" bgcolor="#333399" class="normaltextfield"><div align="left"><font color="#FFFFFF" size="2"><strong>Bienvenid@s <?php echo $_SESSION['usuario'];?></strong></font></div></td>
<td width="49%" bgcolor="#333399" class="normaltextfield"><div align="right"><font color="#FFFFFF" size="2"><strong>Hoy:
<?php echo date("d/m/Y");?> | Cerrar Sesión</strong></font></div></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#333399">
<tr><td><h1><a href="" id="logo">SINFA</a></h1></td>
</tr>
</table>
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#EAEAEA">
<td width="86%" height="75%" valign="top">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
<tr><h3 align="center">Nueva relación de Cateogoria-Linea</h3></tr>
<tr>
<form id="RegForm" name="newcateglinea" action="new_categlinea_exe.php" method="post">
<table bgcolor="" width="100%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#CCCCCC" class="normaltextfield">
<tr>
<td height="29"> <div align="right"><span class="pequeno"><strong><font color="#FF0000">*</font></strong></span>
Categoria:</div></td>
<td><select name="categoria" id="categoria" onchange="cambia_idcat()" style="width:316px;">
<option value="">CATEGORIA</option>
<?php while($tip=mysql_fetch_array($result1)){?>
<option value="<?php echo $tip['id_categoria'];?>"><?php echo $tip['categoria'];?></option>
<?php } ?>
</select><input type="text" id="idcat3" value=""></td>
<td height="29"> <div align="right"><span class="pequeno"><strong><font color="#FF0000">*</font></strong></span>
Linea:</div></td>
<td><select name="linea" id="linea" onchange="cambia_idlin()" style="width:316px;">
<option value="">LINEA</option>
<?php while($tip=mysql_fetch_array($result2)){?>
<option value="<?php echo $tip['id_linea'];?>"><?php echo $tip['linea'];?></option>
<?php } ?>
</select><input type="text" name="id_linea" value="<?php echo $tip['id_linea'];?>" /></td>
</tr>
<tr>
<td height="29"> </td>
<td> </td><td colspan="2"></td>
</tr>
</table>
<table width="54%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td></td><td></td></tr>
<tr>
<td width="48%"><div align="right">
<input name="Agregar" type="submit" id="send" value="Agregar">
</div></td>
<td width="52%"><input name="cancel" type="reset" id="cancel" onClick="MM_goToURL('parent','index.php');return document.MM_returnValue" value="Cancelar"></td>
</tr>
</table>
<table width="48%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr><td></td><td></td></tr>
<tr>
<td width="62%"><div align="right"><span class="pequeno">Los
campos con</span> <span class="titulorojo"><strong><font color="#FF0000">*</font></strong></span>
<span class="pequeno">son obligatorios</span></div></td>
<td width="38%"> </td>
</tr>
</table>
<?php if(isset($_REQUESTT['Agregar'])){
$agregar=$_REQUESTT['Agregar'];
$query="insert into categ_linea (id_categoria,id_linea) values ('$idcategoria','$idlinea')";
$result=mysql_query($query);
if($result){
echo "<script>alert('Registro Insertado Con Exito!');window.location='categlinea_list.php';</script>";
}
else {
echo "<script>alert('Ha ocurrido un error consulte con el Encargado');window.location='categlinea_list.php';</script>";
}
}
?>
</form>
</tr>
</table>
</td>
</table>
</body>
</html>