Foro de elhacker.net

Programación => PHP => Mensaje iniciado por: alexkof158 en 2 Diciembre 2009, 10:58 am



Título: select case sql, enviar form
Publicado por: alexkof158 en 2 Diciembre 2009, 10:58 am
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

Código:
<?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&oacute;: ' . mysql_error());
              
              while($linea = mysql_fetch_array($resultado)){
        
              
               echo " <option value=\"".$linea[0]."\">".$linea[1]."</option>\n";

              }
              ?>
          </select>&nbsp;</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&oacute;: ' . mysql_error());
              
              while($linea = mysql_fetch_array($resultado)){
        
              
               echo " <option value=\"".$linea[0]."\">".$linea[4]."</option>\n";

              }
              ?>
          </select>&nbsp;
</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


Código:
<?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


Título: Re: select case sql, enviar form
Publicado por: alexkof158 en 2 Diciembre 2009, 17:29 pm
nadie me ayuda  :(


Título: Re: select case sql, enviar form
Publicado por: fede_cp en 2 Diciembre 2009, 18:11 pm
Código
  1. <?Php
  2. $servidor = "localhost";
  3. $usuario_bd = "root";
  4. $password_bd = "";
  5. $basedatos = "empresa";
  6.  
  7.  
  8. $conexion = mysql_connect($servidor,$usuario_bd,$password_bd);
  9. if (!$conexion)
  10. {
  11.    echo "Error conectando a la base de datos.";
  12.    exit();
  13. }
  14.  
  15. $resultado=mysql_select_db($basedatos,$conexion);
  16. if (!$resultado)
  17. {
  18.    echo "Error seleccionando la base de datos.";
  19.    exit();
  20. }
  21. ?>
  22. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  23. <html xmlns="http://www.w3.org/1999/xhtml">
  24.  
  25. <head>
  26. <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
  27. <title>Mantenimientos y Servicios</title>
  28. <style type="text/css">
  29. .style2 {
  30. background-color: #3366CC;
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <div id="layer1" style="position: absolute; width: 459px; height: 427px; z-index: 1; left: 10px; top: 15px; visibility: visible;" class="style2">
  36. <form method="post" action="mantyserv.php" style="height: 206px">
  37.  
  38. <h1 align="center">Mantenimiento y Servicios</h1>
  39. <table style="width: 93%; height: 147px;">
  40. <tr>
  41. <td style="width: 148px; height: 45px;">Código</td>
  42. <td style="height: 45px">
  43. <select name="sel_vend" id="sel_vend" style="width: 140px">
  44.            <?php
  45.             $cod_ve = array();
  46.              $cod_vn = array();
  47.             // $c = 0;
  48.              $consulta= "SELECT * FROM empleados ";
  49.                 $resultado = mysql_query($consulta) or die('La consulta fall&oacute;: ' . mysql_error());
  50.  
  51.              while($linea = mysql_fetch_array($resultado)){
  52.  
  53.  
  54.               echo " <option value=\"".$linea[0]."\">".$linea[1]."</option>\n";
  55.  
  56.              }
  57.              ?>
  58.          </select>&nbsp;</td>
  59. </tr>
  60. <tr>
  61. <td style="width: 148px; height: 45px;">Tipo de Mantenimiento</td>
  62. <td style="height: 45px"><select multiple name ="tmant" style="width: 133px">
  63. <option>Limpieza</option>
  64. <option>Completo</option>
  65. <option>Sistema</option>
  66. <option>Otro</option>
  67. </select></td>
  68.  
  69. </tr>
  70. <tr>
  71. <td style="width: 148px">Asignar Técnico</td>
  72. <td>
  73. <select name="sel_vend" id="sel_vend2" style="width: 133px; height: 18px;">
  74.            <?php
  75.              $cod_ve = array();
  76.              $cod_vn = array();
  77.             // $c = 0;
  78.              $consulta= "SELECT * FROM empleados where cargo='Tecnico'";
  79.                 $resultado = mysql_query($consulta) or die('La consulta fall&oacute;: ' . mysql_error());
  80.  
  81.              while($linea = mysql_fetch_array($resultado)){
  82.  
  83.  
  84.               echo " <option value=\"".$linea[0]."\">".$linea[4]."</option>\n";
  85.  
  86.              }
  87.              ?>
  88.          </select>&nbsp;
  89. </td>
  90. </tr>
  91. <tr>
  92. <td style="width: 148px">Valor Asignado $</td>
  93. <td><input name="valor" style="width: 133px" type="text" /></td>
  94. </tr>
  95.  
  96. </table>
  97. <p>Ingrese sus dudas o Notas</p>
  98. <textarea name="notes" style="width: 404px; height: 69px"></textarea>
  99. <input name="Submit1" type="submit" value="Enviar" />
  100. <input name="Reset1" type="reset" value="Limpiar Campos" />
  101. </form>
  102.  
  103. </div>
  104.  
  105. </body>
  106.  
  107. </html>

Código
  1. <?php
  2. $conexion=mysql_connect("localhost","root","") or die("ha ocurrido un error en la conexion");
  3. mysql_select_db("empresa",$conexion) or die("no se ha podido seleccionar la base de datos");
  4. 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");
  5. echo "<h1>Registro de Datos</h1>";
  6. printf("volver");
  7.  printf("<a href= inicio.php>Volver al Inicio</a>");
  8.  
  9. ?>


ahi esta mejor el codigo :)



el error que te dice es el que vos pusiste???, osea "Error conectando a la base de datos".


saludos


Título: Re: select case sql, enviar form
Publicado por: mokoMonster en 27 Febrero 2010, 01:53 am
este codigo esta muy bien hecho xD si pudiera votar por un post seria por este, y otros mas xD hahaha   ;)


Título: Re: select case sql, enviar form
Publicado por: Syphroot en 27 Febrero 2010, 15:55 pm
Al parecer es tu segundo SELECT:

Código:
<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!


Título: Re: select case sql, enviar form
Publicado por: mokoMonster en 28 Febrero 2010, 23:34 pm
Oh mira que bien  xD  :rolleyes: :o