ferpadro Posted September 16, 2007 Share Posted September 16, 2007 I have this function in a script called user_functions.php: <div class="code"> <? function Alquilar($autoalquilar,$fechai,$fechaf) { $sql="INSERT INTO alquiler VALUES ('','$autoalquilar','$_SESSION[id]','$fechai','$fechaf')"; mysql_query($sql) or die(mysql_error()); $sql2="UPDATE auto SET alquilado = 'si' WHERE idauto = '$autoalquilar'"; mysql_query($sql2) or die(mysql_error()); echo "Informacion cargada con exito"; } ?> </div> This function is included in user.php and used whenever the user clicks on the "Alquilar" button: <div class="code"> <?php include('config.inc.php'); include('user_functions.php'); require('session.php'); $val = check_in($_SESSION['usuario'], $_SESSION['contrasena'], $tab); if (strcmp($val,"usuario") != 0) { cambiar("index.php"); return; } else { ?> <html> <head> <form method="post" action=""> <div style="text-align: center;"><big style="font-style: italic;"><big><big><big>-.USUARIO.-</big></big></big></big> <br><br> 1) Realizar Alquiler</br></br> Auto: <select name=autoaalquilar> <? $sql= "SELECT * FROM auto WHERE alquilado = 'no'"; $consulta=mysql_query($sql); while($array = mysql_fetch_array($consulta)) { echo "<option value=$array[0]>$array[1]</option>"; } ?> </select></br> <? echo "$_POST[autoaalquilar]"; ?> Fecha Inicio: Dia:<select name="diai" class="input" id="diai"> <? for ($i = 1; $i < 32; $i++) { if ($i < 10) echo '<option value="0'.$i.'">0'.$i.'</option>'; else echo '<option value="'.$i.'">'.$i.'</option>'; } ?> </select> Mes: <select name="mesi" class="input" id="mesi"> <? for ($i = 1; $i < 13; $i++) { if ($i < 10) echo '<option value="0'.$i.'">0'.$i.'</option>'; else echo '<option value="'.$i.'">'.$i.'</option>'; } ?> </select> Anio: <select name="anioi" class="input" id="anioi"> <? for ($i = 2007; $i < 2100; $i++) { if ($i < 10) echo '<option value="0'.$i.'">0'.$i.'</option>'; else echo '<option value="'.$i.'">'.$i.'</option>'; } ?> </select> </select></br> Fecha Fin: Dia:<select name="diaf" class="input" id="diaf"> <? for ($i = 1; $i < 32; $i++) { if ($i < 10) echo '<option value="0'.$i.'">0'.$i.'</option>'; else echo '<option value="'.$i.'">'.$i.'</option>'; } ?> </select> Mes: <select name="mesf" class="input" id="mesf"> <? for ($i = 1; $i < 13; $i++) { if ($i < 10) echo '<option value="0'.$i.'">0'.$i.'</option>'; else echo '<option value="'.$i.'">'.$i.'</option>'; } ?> </select> Anio: <select name="aniof" class="input" id="aniof"> <? for ($i = 2007; $i < 2100; $i++) { if ($i < 10) echo '<option value="0'.$i.'">0'.$i.'</option>'; else echo '<option value="'.$i.'">'.$i.'</option>'; } ?> </select></br> <input name="opcion" type="submit" value="Alquilar"></br></br> Cancelar un alquiler</br> Alquiler: <select name="autoalquilado"> <? $sql= "SELECT descripcion FROM alquiler JOIN usuario ON alquiler.idusuario = usuario.idusuario JOIN auto ON alquiler.idauto = auto.idauto WHERE (usuario.nombre = '$_SESSION[usuario]')"; $consulta=mysql_query($sql); while($array = mysql_fetch_array($consulta)) { echo "<option value=$array[0]>$array[0]</option>"; } ?> </select> <input name="opcion" value="Cancelar" type="submit"></br></br> Consultar todos los alquileres realizados: <input name="opcion" type="submit" value="Consultar"> </select></br></br> Informar la cantidad de veces que se alquilo cada auto <input type="submit" name="opcion" value="Informar"></br></br> <? $autoalquilar = $_POST['autoaalquilar']; $fechai = $_POST['anioi']."-".$_POST['mesi']."-".$_POST['diai']; $fechaf = $_POST['aniof']."-".$_POST['mesf']."-".$_POST['diaf']; $autoacancelar = $_POST['autoalquilado']; $opcion=$_POST['opcion']; switch($opcion) { case "Alquilar": { Alquilar($autoalquilar,$fechai,$fechaf); break; } case "Cancelar": { Cancelar($autoacancelar); break; } case "Consultar": { Consultar(); break; } case "Informar": { Informar(); break; } } include('pie.php'); } ?> </div> The problem is that when the user clicks on "Alquilar" button, the echo is properly showed on screen but the values are the same the database had before updating it. How can i update the page that shows the information at the same time the user clicks the button? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/69583-re-send-data-after-updating-a-db/ Share on other sites More sharing options...
Dragen Posted September 16, 2007 Share Posted September 16, 2007 where are you echoing the data? it needs to be colected and echoed after it's been updated. Quote Link to comment https://forums.phpfreaks.com/topic/69583-re-send-data-after-updating-a-db/#findComment-349679 Share on other sites More sharing options...
rarebit Posted September 16, 2007 Share Posted September 16, 2007 Dragen is correct, you get through the whole script before you call the 'Alquilar()' function, which then inserts and updates. Quote Link to comment https://forums.phpfreaks.com/topic/69583-re-send-data-after-updating-a-db/#findComment-349680 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.