-1

I have been trying to redirect after inserting into the database but it's not working. The insert is working perfectly but it's not redirecting here is my code

  if (count($errors) == 0) {
    
    $query = "INSERT INTO investment (userid, amount, status, hashID, plan) 
              VALUES('$uidb', '$amount', '$status', '$id', '$plan')";
    $results = mysqli_query($db, $query);
    if (mysqli_num_rows($results) == 1) {
      exit(header('location: https://google.com'));
    }else {
        array_push($errors, "Invalid Sort Code");
    }
  }
Dharman
  • 30,962
  • 25
  • 85
  • 135

1 Answers1

-1

As @AbraCadaver and @Lars Stegelitz commented try this:

but even BETTER DO THIS with prepared statements for a bettter security.

if (count($errors) == 0) {

$query = "INSERT INTO investment (userid, amount, status, hashID, plan) 
          VALUES('$uidb', '$amount', '$status', '$id', '$plan')";
$results = mysqli_query($db, $query);
if (mysqli_affected_rows($db)) == 1) {
  header('location: https://google.com');
}else {
    array_push($errors, "Invalid Sort Code");
}

}