r/PHPhelp • u/recluzeMe • Dec 16 '25
Solved header() function in php
<?php
if(isset($_POST["submitted"]))
{
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$email = $_POST["email"];
$passd = $_POST["passd"];
$confirmPassword = $_POST["Cpassd"];
$conn = new PDO("mysql:hostname=localhost;dbname=signlogin;","root","");
$sqlQuery = "INSERT INTO signup(firstname,lastname,email,PASSWORD,confirmPassword) values('$firstname','$lastname','$email','$passd','$confirmPassword')";
$stmt = $conn->prepare($sqlQuery);
$stmt->execute();
header('Location: http://localhost/phpForm/login.php');
exit();
}
page doesn't redirect to login page hence file login.php is in same folder
http://localhost/login.php
instead of:
http://localhost/phpForm/login.php
?>
View all comments
Show parent comment
1
u/colshrapnel Dec 16 '25
Stinks of AI from a mile away
I actually misread your assumption giving it more credit than it deserves.
The way it's phrased, it suggests that it is possible to redirect a POST request with a regular header location code. Which is nowhere true.
And even if it's a wording problem, the idea implies that the form action or "same page" was /login.php, while the code clearly suggests a signup process, not login.