Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda