hola lo que pasa es que tengo un formulario donde tengo un select case donde extraigo los datos de la cedula y cargo desde la BD pero al momento de enviar el formulario con los datos precargados me dice error en la bd, espero que me haya dado a explicar,
aki dejo los codigos por si acaso
Vista Formulario
<?Php
$servidor = "localhost";
$usuario_bd = "root";
$password_bd = "";
$basedatos = "empresa";
$conexion = mysql_connect($servidor,$usuario_bd,$password_bd);
if (!$conexion)
{
echo "Error conectando a la base de datos.";
exit();
}
$resultado=mysql_select_db($basedatos,$conexion);
if (!$resultado)
{
echo "Error seleccionando la base de datos.";
exit();
}
?>
<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Mantenimientos y Servicios</title>
<style type="text/css">
.style2 {
background-color: #3366CC;
}
</style>
</head>
<body>
<div id="layer1" style="position: absolute; width: 459px; height: 427px; z-index: 1; left: 10px; top: 15px; visibility: visible;" class="style2">
<form method="post" action="mantyserv.php" style="height: 206px">
<h1 align="center">Mantenimiento y Servicios</h1>
<table style="width: 93%; height: 147px;">
<tr>
<td style="width: 148px; height: 45px;">Código</td>
<td style="height: 45px">
<select name="sel_vend" id="sel_vend" style="width: 140px">
<?php
$cod_ve = array();
$cod_vn = array();
// $c = 0;
$consulta= "SELECT * FROM empleados ";
$resultado = mysql_query($consulta) or die('La consulta falló: ' . mysql_error());
while($linea = mysql_fetch_array($resultado)){
echo " <option value=\"".$linea[0]."\">".$linea[1]."</option>\n";
}
?>
</select> </td>
</tr>
<tr>
<td style="width: 148px; height: 45px;">Tipo de Mantenimiento</td>
<td style="height: 45px"><select multiple name ="tmant" style="width: 133px">
<option>Limpieza</option>
<option>Completo</option>
<option>Sistema</option>
<option>Otro</option>
</select></td>
</tr>
<tr>
<td style="width: 148px">Asignar Técnico</td>
<td>
<select name="sel_vend" id="sel_vend2" style="width: 133px; height: 18px;">
<?php
$cod_ve = array();
$cod_vn = array();
// $c = 0;
$consulta= "SELECT * FROM empleados where cargo='Tecnico'";
$resultado = mysql_query($consulta) or die('La consulta falló: ' . mysql_error());
while($linea = mysql_fetch_array($resultado)){
echo " <option value=\"".$linea[0]."\">".$linea[4]."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td style="width: 148px">Valor Asignado $</td>
<td><input name="valor" style="width: 133px" type="text" /></td>
</tr>
</table>
<p>Ingrese sus dudas o Notas</p>
<textarea name="notes" style="width: 404px; height: 69px"></textarea>
<input name="Submit1" type="submit" value="Enviar" />
<input name="Reset1" type="reset" value="Limpiar Campos" />
</form>
</div>
</body>
</html>
Procesar Form
<?php
$conexion=mysql_connect("localhost","root","") or die("ha ocurrido un error en la conexion");
mysql_select_db("empresa",$conexion) or die("no se ha podido seleccionar la base de datos");
mysql_query("insert into mantyserv(sel_vend,tmant,sel_vend2,valor,notes) values('$_REQUEST[sel_vend]','$_REQUEST[tmant]','$_REQUEST[sel_vend2]','$_REQUEST[valor]','$_REQUEST[notes]')", $conexion) or die ("error al registrar datos");
mysql_close();
echo "<h1>Registro de Datos</h1>";
printf("volver");
printf("<a href= inicio.php>Volver al Inicio</a>");
?>
espero me ayudenn..xd
nadie me ayuda :(
<?Php
$servidor = "localhost";
$usuario_bd = "root";
$password_bd = "";
$basedatos = "empresa";
$conexion = mysql_connect($servidor,$usuario_bd,$password_bd);
if (!$conexion)
{
echo "Error conectando a la base de datos.";
exit();
}
$resultado=mysql_select_db($basedatos,$conexion);
if (!$resultado)
{
echo "Error seleccionando la base de datos.";
exit();
}
?>
<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Mantenimientos y Servicios</title>
<style type="text/css">
.style2 {
background-color: #3366CC;
}
</style>
</head>
<body>
<div id="layer1" style="position: absolute; width: 459px; height: 427px; z-index: 1; left: 10px; top: 15px; visibility: visible;" class="style2">
<form method="post" action="mantyserv.php" style="height: 206px">
<h1 align="center">Mantenimiento y Servicios</h1>
<table style="width: 93%; height: 147px;">
<tr>
<td style="width: 148px; height: 45px;">Código</td>
<td style="height: 45px">
<select name="sel_vend" id="sel_vend" style="width: 140px">
<?php
$cod_ve = array();
$cod_vn = array();
// $c = 0;
$consulta= "SELECT * FROM empleados ";
$resultado = mysql_query($consulta) or die('La consulta falló: ' . mysql_error());
while($linea = mysql_fetch_array($resultado)){
echo " <option value=\"".$linea[0]."\">".$linea[1]."</option>\n";
}
?>
</select> </td>
</tr>
<tr>
<td style="width: 148px; height: 45px;">Tipo de Mantenimiento</td>
<td style="height: 45px"><select multiple name ="tmant" style="width: 133px">
<option>Limpieza</option>
<option>Completo</option>
<option>Sistema</option>
<option>Otro</option>
</select></td>
</tr>
<tr>
<td style="width: 148px">Asignar Técnico</td>
<td>
<select name="sel_vend" id="sel_vend2" style="width: 133px; height: 18px;">
<?php
$cod_ve = array();
$cod_vn = array();
// $c = 0;
$consulta= "SELECT * FROM empleados where cargo='Tecnico'";
$resultado = mysql_query($consulta) or die('La consulta falló: ' . mysql_error());
while($linea = mysql_fetch_array($resultado)){
echo " <option value=\"".$linea[0]."\">".$linea[4]."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td style="width: 148px">Valor Asignado $</td>
<td><input name="valor" style="width: 133px" type="text" /></td>
</tr>
</table>
<p>Ingrese sus dudas o Notas</p>
<textarea name="notes" style="width: 404px; height: 69px"></textarea>
<input name="Submit1" type="submit" value="Enviar" />
<input name="Reset1" type="reset" value="Limpiar Campos" />
</form>
</div>
</body>
</html>
<?php
$conexion=mysql_connect("localhost","root","") or die("ha ocurrido un error en la conexion");
mysql_select_db("empresa",$conexion) or die("no se ha podido seleccionar la base de datos");
mysql_query("insert into mantyserv(sel_vend,tmant,sel_vend2,valor,notes) values('$_REQUEST[sel_vend]','$_REQUEST[tmant]','$_REQUEST[sel_vend2]','$_REQUEST[valor]','$_REQUEST[notes]')", $conexion) or die ("error al registrar datos");
mysql_close();
echo "<h1>Registro de Datos</h1>";
printf("volver");
printf("<a href= inicio.php>Volver al Inicio</a>");
?>
ahi esta mejor el codigo :)
el error que te dice es el que vos pusiste???, osea "Error conectando a la base de datos".
saludos
este codigo esta muy bien hecho xD si pudiera votar por un post seria por este, y otros mas xD hahaha ;)
Al parecer es tu segundo SELECT:
<select name="sel_vend" id="sel_vend2" style="width: 133px; height: 18px;">
tienes dos con el mismo nombre, y el codigo que procesa tu form espera la variable "sel_vend2", que supuestamente debería ser tu segundo select ( lo supe por el ID que le asignaste a la etiqueta)
Saludos!
Oh mira que bien xD :rolleyes: :o