Ver Mensaje Individual
  #3 (permalink)  
Antiguo 27/12/2015, 10:40
pilucho
 
Fecha de Ingreso: noviembre-2004
Ubicación: NULL
Mensajes: 655
Antigüedad: 20 años, 2 meses
Puntos: 6
Respuesta: Insertar registro en mysql con php

Prueba asi, revisa tu conexion

tambien te falto action="".....

Código PHP:
Ver original
  1. <form name="ciudadano" method="post"  action="ciudadano.php">
  2.             Nombres<input type="text" name="nombres"></input><br>
  3.             Apellidos<input type="text" name="apellidos"></input><br>
  4.    
  5.             Departamento / Municipio / Barrio:
  6. <?php
  7. function generaSelect()
  8. {
  9.     include 'conexion.php';
  10.     //conectar();
  11.     $consulta=mysql_query("SELECT id, opcion FROM select_1");
  12.     //desconectar();
  13.  
  14.     // Voy imprimiendo el primer select compuesto por los paises
  15.     echo "<select name='select1' id='select1' onChange='cargaContenido(this.id)'>";
  16.     echo "<option value='0'>Elige</option>";
  17.     while($registro=mysql_fetch_row($consulta))
  18.     {
  19.         echo "<option value='".$registro[0]."'>".$registro[1]."</option>";
  20.     }
  21.     echo "</select>";
  22. }
  23. ?>            
  24.             <div id="demo" style="width:600px;">
  25.                 <div id="demoDer">
  26.                     <select disabled="disabled" name="select3" id="select3">
  27.                         <option value="0">Selecciona opci&oacute;n...</option>
  28.                     </select>
  29.                 </div>
  30.                 <div id="demoMed">
  31.                     <select disabled="disabled" name="select2" id="select2">
  32.                         <option value="0">Selecciona opci&oacute;n...</option>
  33.                     </select>
  34.                 </div>
  35.                 <div id="demoIzq"><?php generaSelect(); ?></div>
  36.             </div>            
  37.             <br></br><input type="submit" name="enviar" value="ENVIAR"></input>
  38.         </form>
  39.           <?
  40.           if($_POST["enviar"]!="")    
  41.                 {
  42.            // $sql = "insert into ciudadano (nombres,apellidos,select1,select2,select3) values
  43.            // ('".$_POST["nombres"]."','".$_POST["apellidos"]."','".$_POST["select1"]."','".$_POST["select2"]."','".$_POST["select3"]."')";
  44.                
  45.             $sql = "insert into ciudadano (nombres,apellidos,select1,select2,select3) values  ('$nombres','$apellidos','$select1','$select2','$select3')";
  46.                
  47.                
  48.                 if( mysql_query( $sql, $link ) )            
  49.                 {
  50.             echo "<script language='javascript'>alert('Cliente creado con exito.');</script>";
  51.                 } else {echo 'error:'.mysql_error($link); }
  52.                            
  53.                 }  
  54.                 ?>