Please I'm having issues with redirecting and sql connction

I created a login page, so I want to redirect to the login page after a user registers;
but the header is not working,
i used: header(“location:login.php”); but its not working. I tried to use the redirecting in the website settings but its not what i want. Also i want to know if the details will be saved in the db, i tested it and it was successful, but when i check my db theres nothing there.

here is my code

<?php if(isset($_POST["submit"])){ $servername = "localhost"; $username = "id10948993_task2"; $password = "123"; $dbname = "id10948993_hng_task2"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } mysqli_select_db($conn, 'hng_task2'); $username = $_POST['username']; $email = $_POST['email']; $password = $_POST['password']; $p = " SELECT * from reg_user where email = '$email'"; $result = mysqli_query($conn, $p); $num = mysqli_num_rows($result); if ($num == 1) { echo ""; header("location:index.php"); }else{ $reg= "INSERT INTO reg_user(username , email , password ) values ('$username' , '$email', '$password')"; mysqli_query($conn, $reg); $reg= "INSERT INTO reg_user(username , email , password ) values ('$username' , '$email', '$password')"; echo ""; header("location:login.php"); } } ?>

Add this to your .htaccess and then try again.

php_flag output_buffering on

PDO is a great method of connection and working with database.

This topic was automatically closed after 23 hours. New replies are no longer allowed.