Ver Mensaje Individual
  #30 (permalink)  
Antiguo 22/11/2015, 17:24
pilucho
 
Fecha de Ingreso: noviembre-2004
Ubicación: NULL
Mensajes: 652
Antigüedad: 19 años, 5 meses
Puntos: 6
Respuesta: mysqli_insert_id en un campo de texto

Cita:
Iniciado por gonzaherrera77 Ver Mensaje
pilucho capaz que esto te pueda ayudar. http://phpya.com.ar/temarios/descrip...d=80&inicio=50

¡Saludos!

Probe asi quite esto ¨}¨ y le puse mas abajo y dejo de salir el error pero envia vacio





Código PHP:
Ver original
  1. <?php
  2.     include_once('conectar.php'); // Conexion
  3.     $conexion = mysqli_connect($dbhost,$dbuser,$dbpass,$dbdatabase) or die ('error');   // Verificar Conexión
  4.  
  5. if(isset($_REQUEST['enviar'])) {
  6.     if (mysqli_connect_errno()) {
  7.        echo "Error MySQL: " . mysqli_connect_error();
  8.     }
  9.  
  10.     if (isset($_GET['idp'])) {
  11.        $idp = $_GET['idp']; // ID de Personas
  12.        $Nombre = $_POST['Nombre'];
  13.        $Apellido = $_POST['Apellido'];
  14.        $Anio = $_POST['Anio'];
  15.        $CodigoUnico = $_POST['CodigoUnico'];
  16.        $SQL = "INSERT INTO Personas (Nombre,Apellido,Anio,CodigoUnico) VALUES ('$Nombre','$Apellido','$Anio','$CodigoUnico')";
  17.      
  18.  
  19.     if (mysqli_query($conexion,$SQL)) {
  20.        echo "Listo";
  21.        // Print auto-generated id
  22.        //echo " " . mysqli_insert_id($conexion);
  23.       $last_id = mysqli_insert_id($conexion);
  24.       echo "ID es: " . $last_id; // AQUI SOLO ME MUESTRA EL ID INGRESADO AL DB
  25.     }
  26.     else {
  27.        echo "Error: " . $SQL . "<br>" . mysqli_error($conexion);
  28.    }
  29. }
  30.  
  31. }
  32. ?>
  33.  <!DOCTYPE html>
  34.  <html>
  35.     <head>
  36.        <meta charset="utf-8">
  37.        <title>Test</title>
  38.     </head>
  39.     <body>
  40.       <form action="tes.php" method="post">
  41.          <input name="Nombre" type="text">
  42.          <input name="Apellido" type="text">
  43.          <input name="Anio" type="text">
  44.          <input name="CodigoUnico" type="text" value="<?php $last_id = (isset($last_id)) ? $last_id : ""; echo $last_id;?>">
  45.          <input name="enviar" type="submit">
  46.       </form>
  47.     </body>
  48.  </html>