2015-10-19 53 views
1

我一直在为我的网站做一个注册表,但我发现我遇到了麻烦。重定向到索引,php

这是我的注册表单代码(PHP文件)

<?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"); 
    } 


} ?> 

其所有现在好了,但是当我提交登记表格此重定向我到此: “http://localhost/upbyte/App/index.php”我只是想重定向到:​​

谢谢。

回答

1

您可以使用header();将用户重定向,

做定时重定向,

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

做一个即时重定向,

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

阅读材料

How to fix "Headers already sent" error in PHP

+0

,但在错误的文件夹中的文件。推测他的'utils :: redirectToUrl'函数执行这个'header()'调用。 – Barmar

+0

@Barmar是我的功能是执行标题:D –

2

那么这取决于,如果有一个名为index.php的在upbite的应用程序目录之前,你可能只是将其指向了错误的文件位置的文件。 尝试改变从 utils::redirectToUrl("../index.php"); 链接 utils::redirectToUrl("/../index.php"); 你可能错过了他** **被重定向指数

+0

ohh谢谢,那作品:D –

+0

@TomasAlmeida没问题:)只是一个问题:Português? – ImInThatCorner

+0

'/../'没有意义。 '/'表示根文件夹,'../'表示升一级。但是你不能从根上去。 – Barmar