2015-10-19 115 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