Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] Por que no me crea el registro ??

Estas en el tema de Por que no me crea el registro ?? en el foro de PHP en Foros del Web. Hola amigos: Tengo este codigo que busca en una tabla segun un numero de registro, en caso de no encontrarlo lo crea (al final), alguien ...
  #1 (permalink)  
Antiguo 21/06/2018, 10:13
 
Fecha de Ingreso: noviembre-2003
Mensajes: 499
Antigüedad: 20 años, 4 meses
Puntos: 7
Por que no me crea el registro ??

Hola amigos:
Tengo este codigo que busca en una tabla segun un numero de registro, en caso de no encontrarlo lo crea (al final), alguien me puede decir por que no lo crea ??

Código PHP:
<HTML>
<head> 
  <title>Modificación</title> 
  <style>

.mitabla {
    font: normal  12px Verdana, Geneva, Arial, Helvetica, sans-serif;
    color: #0033FF;
    background: #B0C4DE;
    text-align: left;
  width: 98%;
  
}

.mitabla, .mitabla td , .mitabla th {  border: 0px solid; }

.mitabla th {  background: #4682B4;  color: #00008B; }

</style>
</head>   
<body> 
   
  <?php 
$Pre 
$_GET['regi'];
echo 
$Pre;
    
$mysql=new mysqli("localhost","root","","htl"); 
    if (
$mysql->connect_error
      die(
"Problemas con la conexión a la base de datos"); 
    
   
    
$registro=$mysql->query("select * from tarifas where nr ='$_REQUEST[regi]' LIMIT 4") or 
      die(
$mysql->error); 
      
//_________________________________________________________________________
while ($reg=mysqli_fetch_array($registro))
{
  
?>

  <table align='center'  class='mitabla'>
  <tr>
  <th>Single</th>
  <td><?php echo $reg['single'];?></td>
  <th>Doble</th>
  <td><?php echo $reg['doble'];?></td>
  <th>Triple</th>
  <td><?php echo $reg['triple'];?></td>
  <th>Cuadruple</th>
  <td><?php echo $reg['cuadr'];?></td>
  <th>Dpto.2P:</th>
  <td><?php echo $reg['dpto2p'];?></td>
  <th>Dpto.3P:</th>
  <td><?php echo $reg['dpto3p'];?></td>
  <th>Iva:</th>
  <td><?php echo $reg['iva'];?></td>
  <th>Fecha:</th>
  <td><?php echo $reg['fecha'];?></td>
  </tr>
  <hr/>
  </table>
<?php 
 
  
}
      
//_________________________________________________________________________
$registro=$mysql->query("select * from tarifas where nr ='$_REQUEST[regi]'") or 
      die(
$mysql->error);       
    if (
$reg=$registro->fetch_array()) 
    { 
  
$Pre $_GET['regi'];
echo 
$Pre;
  
?> 
<table  align='center'  class='mitabla'>
    <form method="post" action="pagina3.php">
  <input type="hidden" name="Pre" value="<?php echo $Pre ?>"/>
  <tr>
  <th>Single</th>
  <td><input type="text" style="width : 30%" name="valsing"  value="<?php echo $reg['single']; ?>"/></td>
  <th>Doble</th>
  <td><input type="text" style="width : 30%" name="valdob"  value="<?php echo $reg['doble']; ?>"/> </td>
  <th>Triple</th>
  <td><input type="text" style="width : 30%" name="valtrip"  value="<?php echo $reg['triple']; ?>"/></td>
  <th>Cuadruple</th>
  <td><input type="text" style="width : 30%" name="valcuad"  value="<?php echo $reg['cuadr']; ?>"/> </td>
  <th>Dpto.2P:</th>
  <td><input type="text" style="width : 30%" name="valdep2"  value="<?php echo $reg['dpto2p']; ?>"/></td>
  <th>Dpto.3P:</th>
  <td><input type="text" style="width : 30%" name="valdep3"  value="<?php echo $reg['dpto3p']; ?>"/></td>
  </tr>
  <tr>
  <th>Dpto.4P:</th> 
  <td><input type="text" style="width : 30%" name="valdep4"  value="<?php echo $reg['dpto4p']; ?>"/></td>
  <th>Dpto.5P:</th>
  <td><input type="text" style="width : 30%" name="valdep5"  value="<?php echo $reg['dpto5p']; ?>"/> </td>
  <th>Dpto.6P:</th>
  <td><input type="text" style="width : 30%" name="valdep6"   value="<?php echo $reg['dpto6p']; ?>"/> </td>
  <th>Dpto.7P:</th> 
  <td><input type="text" style="width : 30%" name="valdep7"  value="<?php echo $reg['dpto7p']; ?>"/></td>
  <th>Dpto.8P:</th>
  <td><input type="text" style="width : 30%" name="valdep8"  value="<?php echo $reg['dpto8p']; ?>"/> </td>
  <th>Suite:</th>
  <td><input type="text" style="width : 30%" name="valsuit"  value="<?php echo $reg['suite']; ?>"/> </td>
  </tr>
  <tr>
  <th>Pens.Compl:</th>
  <td><input type="text" style="width : 30%" name="pcomp"  value="<?php echo $reg['pecomp']; ?>"/></td>
  <th>Media P:</th>
  <td><input type="text" style="width : 30%" name="valmp"  value="<?php echo $reg['mediap']; ?>"/> </td>
  <th>Desayuno:</th>
  <td><input type="text" style="width : 30%" name="valdesa"  value="<?php echo $reg['desayuno']; ?>"/> </td>
  <th>Alm./Cena:</th>
  <td><input type="text" style="width : 30%" name="alcen"  value="<?php echo $reg['almcena']; ?>"/> </td>
  <th>Bac1:</th>
  <td><input type="text" style="width : 30%" name="baco1"  value="<?php echo $reg['bcomun1']; ?>"/> </td>
  <th>Bac2:</th>
  <td><input type="text" style="width : 30%" name="baco2"  value="<?php echo $reg['bcomun2']; ?>"/> </td>
  </tr>
  <tr>
  <th>Bac3:</th>
  <td><input type="text" style="width : 30%" name="baco3"  value="<?php echo $reg['bcomun3']; ?>"/> </td>
  <th>Bac4:</th>
  <td><input type="text" style="width : 30%" name="baco4"  value="<?php echo $reg['bcomun4']; ?>"/> </td>
  <th>Iva:</th>
  <td><input type="text" style="width : 30%" name="iva"  value="<?php echo $reg['iva']; ?>"/> </td>
  <td></td>
  <td><input type="submit" value="Confirmar"></td>
  </tr>
   

  <tr>
  </tr>
  <tr>
  </table>
      
    </form> 
  <?php 
    
}       
    else 
      
//echo 'No existe este prestador'; 
    
mysqli_query($mysql,"insert into tarifas (nr) values ($Pre)"); 
    echo 
'creado'
    
$mysql->close(); 

  
?>   
</body>
</HTML>
  #2 (permalink)  
Antiguo 21/06/2018, 13:19
 
Fecha de Ingreso: abril-2006
Mensajes: 583
Antigüedad: 18 años
Puntos: 120
Respuesta: Por que no me crea el registro ??

Pues por que tu variable $Pre = $_GET['regi']; es VACIA,

en acmbio cuando mandas informacion desde tu formulario lo haces VIA POST
asi que dedusco que tu error se arregla si usas
$Pre = $_POST['regi']; en lugar de $Pre = $_GET['regi'];

o bien cambia el "method=post" de tu formulario por uno get
  #3 (permalink)  
Antiguo 22/06/2018, 05:28
 
Fecha de Ingreso: noviembre-2003
Mensajes: 499
Antigüedad: 20 años, 4 meses
Puntos: 7
Respuesta: Por que no me crea el registro ??

la variable no llega vacia, la imprimo y lleva el contenido, pero no crea el registro

Etiquetas: crea, html, mysql, query, registro, select, sql, tabla
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:11.