Jump to content

Re-send data after updating a DB


ferpadro

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/69583-re-send-data-after-updating-a-db/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.