How to call the id of my SQL database and show it in a query with PHP?

-2

I have a form, where users enter personal data. I did an if, so that the CURP was not repeated, if the curp is repeated it sends an alert telling them that it is repeated and it returns them to the form, in that I do not have problem it seems to me, but in the else of that condition, that is to say when enter a curp that is not repeated in the base, execute the insertion of the data that the user filled in the form to the database and after that, I make a declaration of variables calling the data that the user filled with the method $ _REQUEST and in the end I print them, but what I want is to also print the id of the user that is registering, for this I need a query in my database and what I want is to select the id of the user where my field CURP is equal to the CURP that you entered in user, to indicate that this is your id and that you must save it, but it does not work out, this is my code.

<?php
 $conexion=mysql_connect("localhost","id6681618_pagina26","aldair1234")
 or die ("Problemas en la conexion");
 mysql_select_db("id6681618_pagina26",$conexion)
 or die("Problemas en la conexion de la base de datos");
 $inscripciones=mysql_query("SELECT FOLIO, CURP
 FROM inscripciones where
 CURP='$_REQUEST[CURP]'",$conexion) or
 die("Problemas en el select:".mysql_error());

 if($reg=mysql_fetch_array($inscripciones))
 {
   $mensaje = "Este CURP ya fue ingresado, por favor intenta nuevamente.";
 echo "<script>";
 echo "alert('$mensaje');";
 echo "history.back();";
 echo "</script>";
 //redirect('formulario.html', 'refresh');
 //header( "refresh:5;url=formulario.html" );



}

This is the else:

else
 {

  mysql_query("insert into inscripciones(NOMBRE, APELLIDOPA, APELLIDOMA, CURP) values ('$_REQUEST[NOMBRE]','$_REQUEST[APELLIDOPA]','$_REQUEST[APELLIDOMA]','$_REQUEST[CURP]')", $conexion) or die("Problemas en el select".mysql_error());
mysql_close($conexion);
 print '<script language="JavaScript">'; 


print 'alert("Proceso terminado");';

    print '</script>'; 

    }

Then I do my variables and finish the PHP:

$nom=$_REQUEST['NOMBRE'];
$apellipa=$_REQUEST['APELLIDOPA'];
$apellima=$_REQUEST['APELLIDOMA'];
$curp=$_REQUEST['CURP'];
?>

And now the impressions follow, that is, the query, this is for the user to check if his data is correct or not, but he does not show me the first id, he appears blank, when he reloads the page he shows it to me, but the CURP code returns me immediately to the form.

<h1>Verifica que los datos que ingresaste sean correctos, si así lo es, presiona para generar tu ficha.</h1>


 <form action="eliminar.php">


 <div  class="col-4">
    <label>
      FOLIO
    <input name="FOLIO" type="text"  disabled="false" value="<?php echo $reg['FOLIO']; ?>" />    
    </label>
  </div>

   <div  class="col-4">
    <label>
      NOMBRE
      <input name="NOMBRE" type="text"  disabled="false" value="<?php echo $nom ?>" />    
      </label>
  </div>


<div class="col-4">
    <label>
      APELLIDO PATERNO
      <input name="APELLIDOPA" type="text" disabled="false" value="<?php echo $apellipa ?>" />
    </label>
  </div>


  <div class="col-4">
    <label>
      APELLIDO MATERNO
      <input name="APELLIDOMA" type="text" disabled="false" value="<?php echo $apellima?>" />
    </label>
  </div>


  <div class="col-3">
    <label>
      CURP
      <input name="CURP" type="text" disabled="false" value="<?php echo $curp ?>" />
    </label>
  </div>

I would really appreciate it if you can help me, I've been thinking about how to do it for several days. : 'v

    
asked by Oscar Reyes 31.08.2018 в 09:32
source

1 answer

0

first of all, the mysql function is already obsolete, in the new PHP versions mysqli is used, so you should update your code.

Here I leave your code with some improvements

Your Main form: (Form.php)

<form action="procesar.php" method="POST">
  <div  class="col-6"><label>NOMBRE</label>
    <input name="NOMBRE" type="text"  />    
  </div>
  <div class="col-6"><label>APELLIDO PATERNO</label>
    <input name="APELLIDOPA" type="text"/>
  </div>
  <div class="col-6"><label>APELLIDO MATERNO</label>
   <input name="APELLIDOMA" type="text"/>
  </div>
  <div class="col-6"><label>CURP</label>
    <input name="CURP" type="text"  />
  </div>
  <button type="submit" name="btnRegistrar">REGISTRAR</button>
</form>

Then in PHP : (proces.php)

<?php
$conexion=mysqli_connect("localhost","root","","stackover");

if (isset($_POST['btnRegistrar'])) {
 $nom=$_REQUEST['NOMBRE'];
 $apellipa=$_REQUEST['APELLIDOPA'];
 $apellima=$_REQUEST['APELLIDOMA'];
 $curp=$_REQUEST['CURP'];
 $query = "SELECT FOLIO, CURP FROM inscripciones where CURP='$curp'";
 $inscripciones=mysqli_query($conexion,$query);

 if($reg=mysqli_fetch_array($inscripciones)){
   $mensaje = "Este CURP ya fue ingresado, por favor intenta nuevamente.";
   echo "<script>";
   echo "alert('$mensaje');";
   echo "history.back();";
   echo "</script>";
   //redirect('formulario.html', 'refresh');
   //header( "refresh:5;url=formulario.html" );
 } else {
   $instruccion = "INSERT INTO inscripciones(NOMBRE, APELLIDOPA, APELLIDOMA, CURP) values ('$nom','$apellipa','$apellima','$curp')";
   mysqli_query($conexion,$instruccion);
   print '<script language="JavaScript">'; 
   print 'alert("Proceso terminado");';
   print '</script>'; 
}
?>
<h1>Verifica que los datos que ingresaste sean correctos, si así lo es, presiona para generar tu ficha.</h1>
<form action="eliminar.php">
  <div  class="col-4"><label>FOLIO</label>
    <input name="FOLIO" type="text"  disabled="false" value="<?php echo $reg['FOLIO']; ?>" />    
  </div>
   <div  class="col-4"><label>NOMBRE</label>
      <input name="NOMBRE" type="text"  disabled="false" value="<?php echo $nom; ?>" />    
  </div>
  <div class="col-4"><label>APELLIDO PATERNO</label>
      <input name="APELLIDOPA" type="text" disabled="false" value="<?php echo $apellipa; ?>" />
  </div>
  <div class="col-4"><label>APELLIDO MATERNO</label>
      <input name="APELLIDOMA" type="text" disabled="false" value="<?php echo $apellima; ?>" />
  </div>
  <div class="col-4"><label>CURP</label>
      <input name="APELLIDOMA" type="text" disabled="false" value="<?php echo $curp; ?>" />
  </div>
</form>
<?php } else { echo ":("; } ?>

I hope to help you, Good morning =)

    
answered by 01.09.2018 в 20:30