Tomas Duarte
Tomas Duarte

Reputation: 127

Redirect to index,php

i have been doing a register form for my website but i found me on a trouble.

This is my register form code(PHP File)

    <?php
include("../libraries/Security.php");
include("../includes/utils.inc");

$host = "localhost";
$userSQL = "root";
$pwSQL = "";
$db = "upbyte";

$con = mysqli_connect($host,$userSQL,$pwSQL,$db);

$username = Security::xss_clean($_POST['username']);
$name = Security::xss_clean($_POST['name']);
$email = Security::xss_clean($_POST['email']);
$password = Security::xss_clean($_POST['password']);

$sql = "SELECT email FROM users WHERE email='$email'";
$result = mysqli_query($con,$sql);

$insert = "INSERT INTO users(name,username,password,email) VALUES('$name','$username',md5('$password'),'$email')";

if(isset($_POST['Register'])){

    if(mysqli_num_rows($result) == 1){
        echo "Sorry...This email already exist..";
    }

    if(empty($username) && empty($name)&& empty($password)&& empty($email)) {
        print('Fill all the fields!');
    }else if(mysqli_num_rows($result) == 1){
            echo "Sorry...This email already exist..";
    }else{
        mysqli_query($con,$insert);
        echo "Register Completed!";
        utils::redirectToUrl("../index.php");
    }


} ?>

Its all good now, but when i submit the register form this redirect me to this: "http://localhost/upbyte/App/index.php" and i just want redirect to: http://localhost/upbyte/index.php

Thanks.

Upvotes: 1

Views: 90

Answers (2)

ImInThatCorner
ImInThatCorner

Reputation: 31

Well it depends, if there is a file called index.php before the App directory in upbite, you're probably just pointing it to the wrong file location. Try changing the link from utils::redirectToUrl("../index.php"); to utils::redirectToUrl("/../index.php"); You probably missed an index

Upvotes: 2

Script47
Script47

Reputation: 14540

You can use header(); to redirect a user,

to do a timed redirect,

exit(header("Refresh: $time; URL=$page"));

to do an instant redirect,

exit(header("Location: $page"));

Reading Material

How to fix "Headers already sent" error in PHP

Upvotes: 1

Related Questions