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>