Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
How do I redirect after executing PHP action and return a value (and force a browser redirect if possible)?

Please I created a form with an action page. That retrieves a value from MySQL database column.

The form submits quite alright and the data is retrieved, too. But the problem is the header('Location: home.php'); has refused to redirect the user back home after the information has been retrieved. Plus, the user needs to refresh the browser before they see the retrieved data so I don't know it is possible to do the following:

  1. Redirect to the homepage after the action has been executed,
  2. return the value (which is stored in a variable) back to the homepage.

By the way, this is the PHP action page:

<?php
session_start();
include(cafedbconfig.php);

$cafeconnection = mysqli_connect('localhost', 'dbuser', 'dbpass', 'dbname');
$query = "SELECT name, email, password, balance FROM cafeusers WHERE username = '".$_SESSION['username']."'";
$result = mysqli_query($cafeconnection, $query) or die (mysqli_error($MyConn));
if ($row = mysqli_fetch_assoc($result)){
    $balance = (int) stripslashes($row["balance"]);
    $email = $row["email"];
    $name = $row["username"];
    $cafepass = $row["password"];


    
}
mysqli_free_result($result);

    if(isset($_POST['cafepass'])){
        $pass = $_POST['cafepass'];
        $newbalance1 = $balance - 50;
               
        $select = "UPDATE cafeusers SET balance = '$newbalance1' WHERE username='$name' AND password='$pass'";
}
        if (mysqli_query($cafeconnection, $select)) {
  $returnvalue = "VIP 1 Upgraded successfully!";
} else {
  $returnvalue = "Error" . mysqli_error($cafeconnection);
}
mysqli_close($cafeconnection);
    return $returnvalue;
    header ('Location: home.php');
?>

I want to redirect to home.php after this action has been executed and then return with $returnvalue back to home.php because I intend to use the said variable.

if possible, force a browser refresh after doing so. I'd really appreciate the help. Cheers.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda