Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/05/2008, 14:54
hj1318
 
Fecha de Ingreso: mayo-2008
Mensajes: 8
Antigüedad: 16 años
Puntos: 0
Sumar, Multiplica Variables con un controlador (PHP MYSQL)

Hola, nesecito ayuda, es el crédito de síntesis, y tengo que hacer una web de hoteles, la parte de administrador esta hecha, la reserva de habitaciones tambien, pero donde tengo problemas es en el 30% del coste que tengo que mostrar al cliente cuando kiera saber el precio o lo que tiene que pagar.
cada ckechbox tiene un valor diferente, hecho por un controlador las habitaciones tambien pero no cuando le doy al boton de calcular me da 0, si alguien me puede ayudar, deja un mensaje.
gracias de ante mano.
El codigo es el siguente:


<?php
include("seguridad.php");
?>
<html>
<head>
<title>Buscar Hotel</title>
<link rel="stylesheet" type="text/css" href="estilo2.css">

</head>
<body>
<align=center>
<br>
<br>
<br>
<br>
<h1> Página de Reserva</h1>
<br>
<br>
<?php

// CONECTAMOS CON EL SERVIDOR
$conn=mysql_connect("localhost","root","");
if (!$conn)
{
$x=mysql_error();
echo("Error al conectar al servidor: $x");
}

//Seleccionamos la DDBB
$err_db=mysql_select_db("cs");
if (!$err_db)
{
$x=mysql_error();
echo("Error al seleccionar la bbdd: $x");
}

// COMENZAMOS CON EL FORMULARIO
echo "<form method='POST' action='reservar.php'>";
echo "<table align='center' border='1' bgcolor='#E8F4CD'>";

echo "<tr>";
// SELECT DE HOTELES A ELIEGIR
$sql="select idhotel, hotel from hotel order by hotel";
//DECLARO ERRO
if ( ! $resul=mysql_query($sql))
{
echo "el select de la tabla para el desplegable NO se ha realizado";
}

echo "<td> <font color='3366CC'>*Hotel:</font></td>";
echo"<td>";
echo "<select name='idhotel'>";
// MOSTRARE EL RESULTADO DEL SELECT
while ($row= mysql_fetch_array($resul))
{

if ($_POST['idhotel']==$row[0])
{
echo "<option selected style=color:'green' value='$row[0]'>$row[1]</option>";
}
else
{
echo "<option style=color:'green' value='$row[0]'>$row[1]</option>";
}

}

echo "</select>";
echo "</tr>";

echo "<tr>";
$fechainicio=@$_POST['fechainicio'];
echo "<td><font color='3366CC'>*Fecha Entrada:</font></td>";
echo "<td><input type=text style=color:'green' name='fechainicio' value='$fechainicio' maxlength='10'>";
echo "</td>";
echo "</tr>";

echo "<tr>";
$fechafinal=@$_POST['fechafinal'];
echo "<td><font color='3366CC'>* Fecha Salida:</font></td>";
echo "<td><input type=text style=color:'green' name='fechafinal' value='$fechafinal' maxlength='10'>";

echo "<input type='submit' name='envia' value='consultar habitaciones'></td>";
echo "</td>";
echo "</tr>";


echo "<tr>";
echo "<td><font color='3366CC'>* Numero de Habitacion, Precios:</font></td>";
echo "</td>";

$idhotel=@$_POST['idhotel'];

$fechainicio=@$_POST['fechainicio'];

$fechafinal=@$_POST['fechafinal'];
echo"</form>";


//////-----------RESULTADO DE LA BUSQUEDA DE HABITACIONES POR HOTEL Y FECHAS-----------///////
if(isset($_POST['envia']))
{
if (@$_POST['idhotel'] != "" AND $_POST['fechainicio'] !="" AND $_POST['fechafinal'] !="")
{

$sqll="select numhabitacion , idhotel , precio , habitaciones.idtipo , tipo.tipo FROM `habitaciones` , `tipo` WHERE idhotel='$idhotel' AND tipo.idtipo=habitaciones.idtipo AND (habitaciones.numhabitacion, habitaciones.idhotel)
NOT IN (select habitreserva.numhabitacion, habitreserva.idhotel FROM `habitreserva` , `reserva` WHERE habitreserva.idhotel='$idhotel'
AND reserva.fechainicio>='$fechainicio' AND reserva.fechafinal<'$fechafinal' OR '$fechainicio'>=reserva.fechainicio
AND '$fechainicio'<reserva.fechafinal OR '$fechafinal'>=reserva.fechainicio AND '$fechafinal'<reserva.fechafinal
AND habitreserva.idreserva=reserva.idreserva)";

$resull=@mysql_query($sqll);
if(!$resull) {
$x=mysql_error();
echo("Error al realizar la busqda d habitacions, $x<br>");

}


echo "<td>";
// si el resultado de las habitacones es 0

$cantidad=mysql_num_rows($resull);

if ($cantidad == 0)
{
echo "<div align=center><FONT COLOR=FF3300 SIZE=3> No hay habitaciones disponibles para las fechas seleccionadas</font></div>";
exit;
}
else
{
$contable=0;
$total=0;
echo "<FONT COLOR='3366CC'> Nº de Habitaciones |&nbsp; &nbsp; Precio &nbsp; &nbsp; |&nbsp; &nbsp; Categoria </font><br>";
while ($row2= mysql_fetch_array($resull))
{
$contable= $contable+1;


echo "&nbsp; &nbsp; <input type='checkbox' name='numhabitacion".$contable."' style=color:'green' value='$row2[0]'> &nbsp; $row2[0]";
echo "<input type='hidden' name='precio".$total."' style=color:'green' value='$row2[2]'> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; $row2[2]€";

echo "<input type='hidden' name='tipo' style=color:'green' value='$row2[0]'> &nbsp; &nbsp; |&nbsp; &nbsp; &nbsp; $row2[4]<br>";

$total=$total+$row2[2];
}
}

echo "</td>";
echo "</td>";
echo "</select>";
echo "</tr>";
}
else
{
echo " <div align=center> <FONT COLOR=FF3300 SIZE=2 > Verifique las fechas, no puede dejar un campo en blanco </font></div>";
exit;
}
$_SESSION['contable']=@$contable;
$_SESSION['total']=@$total;


echo "<tr>";
$dni=@$_POST['dni'];
echo "<td><font color='3366CC'>* D.N.I:</font></td>";
echo "<td><input type=text style=color:'green' name='dni' value='$dni' maxlength='9'>8 numeros 1 Letra";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td><font color='3366CC'>* Noches:</font></td>";
echo "<td><input type=text style=color:'green' name='noches' maxlength='2'>";
echo "</td>";
echo "</tr>";



echo "<tr>";
$sql3="select * from regimen order by regimen";
if ( ! $resul3=mysql_query($sql3))
{
echo "el select de la tabla para el desplegable NO se ha realizado";
}
echo "<td> <font color='3366CC'>Regimen mínimo:</font></td>";
echo"<td>";
echo "<select name='idregimen'>";
while ($row3= mysql_fetch_array($resul3))
{
echo "<option style=color:'green' value=".$row3['idregimen'].">".$row3['regimen']."</option>";
}
echo "</td>";
echo "</select>";

echo "</tr>";
echo "</table>";


echo"<INPUT name=reservar TYPE=SUBMIT value=Reservar>";
echo"<input name='DELETE' type='RESET' value='Borrar datos editados'>";
echo"<INPUT name=clclr TYPE=SUBMIT value=Calcular el Precio de la Reserva >";
echo "</form>";
}


////////---------TOTAL Y 30% A PAGAR ---------/////////////
$dni=@$_POST['dni'];
$fechainicio=@$_POST['fechainicio'];
$fechafinal=@$_POST['fechafinal'];
$idregimen=@$_POST['idregimen'];
$noches=@$_POST['noches'];
$pagar=@$_POST['precio.$pagar.'];

///---CALCULO DEL 30% Y TOTAL ---///////
if (isset($_POST['clclr'])){

echo "<table align='center' border='1' bgcolor='#E8F4CD'>";
echo "<tr>";
echo "<td>";

$pagar=1;
$_SESSION['total']=@$total;
if ($total <= $_SESSION['total'])
{

$pagar=@$_POST['precio'.$total];
echo "<br>";
echo $noches;
echo "<br>";
echo $pagar ;
echo "<br>";

$calculo=$pagar*$noches;
echo $calculo ;
echo "<br>";
echo $total ;
$resultado=$calculo*30/100;
echo $resultado;
echo "<br>";
echo "El 30% de su reserva es $resultado €";

echo "<td>";
echo "<tr>";

echo "<table>";
}
}



////////////*COMIENZA LA RESERVA*///////////


$dni=@$_POST['dni'];
$fechainicio=@$_POST['fechainicio'];
$fechafinal=@$_POST['fechafinal'];
$idregimen=@$_POST['idregimen'];
$noches=@$_POST['noches'];



if (isset($_POST['reservar'])){

if (@$_POST['dni'] != "" AND $_POST['fechainicio'] !="" AND $_POST['fechafinal'] !="" AND $_POST['noches'] !="")

{
$result="INSERT INTO `reserva` ( `dni` ,`fechainicio` , `fechafinal` , `idregimen` , `noches` )
VALUES ('$dni', '$fechainicio', '$fechafinal', '$idregimen', '$noches');" ;

$sql=@mysql_query($result);





$query89="SELECT idreserva FROM reserva WHERE dni='$dni' AND fechainicio='$fechainicio'
AND fechafinal='$fechafinal' AND idregimen='$idregimen'
AND noches='$noches'";
$sel=@mysql_query($query89);



echo $_SESSION['contable'];
while ($in= mysql_fetch_array($sel))
{

$contable=1;

while($contable <= $_SESSION['contable'])
{
$numhabitacion=@$_POST['numhabitacion'.$contable];
$idhotel=@$_POST['idhotel'];

$query12="INSERT INTO `habitreserva` ( `idreserva` , `idhotel` , `numhabitacion` )
VALUES ('$in[0]', '$idhotel', '$numhabitacion')";

$query45=mysql_query($query12);


$contable=$contable+1;


echo $query12;
echo" Su reserva se a realizado con exito" ;

}

}
}

else
{
echo " <div align=center> <FONT COLOR=FF3300 SIZE=2 > Verifique sus datos no puede dejar un campo en blanco </font></div>";
}
}
?>

</body>
</html>

Última edición por hj1318; 28/05/2008 a las 15:39