Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!