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
2
u/HolyGonzo Dec 16 '25
Not everybody is trying to karma farm (the sub isn't even big enough to really do that in any meaningful way), and hopefully it everybody is telling the OP something, it will sink in as an important thing to do.
There are other important things they missed - password hashing, checking the results of the query, etc... and while they are all very important, SQL injection is probably the most important of the immediate concerns.
My gut says that this person is on an initial page called login.php as part of a registration flow and they want to redirect to a different login.php in a different folder but it's unclear.