2017-04-15 66 views
-1

它应该REQUIRE_ONCE(“registo.php”),当我尝试注册一个用户的用户名已经存在,而不是它进入我的login.php,标题位置重定向到“registo.php?p = registo ?e = true“,所以问题出现在”index.php“中,但我不知道什么是错的,什么都没有?PHP第二个标记不起作用,什么错了?

register.php

$query = "SELECT username FROM login WHERE username = '$user'"; 
     $result = mysqli_query($db, $query); 
     if (!$result) { 
      echo ' Database Error Occured '; 
     } 

     if (mysqli_num_rows($result) == 0) { 


$sql = "INSERT INTO `login` (`id`,`username`,`password`) VALUES (NULL, '".$user."', '".$pass."');"; 
if(!mysqli_query($db, $sql)){ 
    echo 'Não foi possivel salvar os dados!'; 
}else{ 
$_SESSION['message'] = 'success'; 
header("location: index.php?p=registo?success=1"); 

} 
}else{header("location: index.php?p=registo?e=true");} 
}else 
{ 
    echo 'Os campos não estão definidos!'; 
    } 

的index.php

<div class="container"> 
     <?php 
     if (isset($_GET['p']) && $_GET['p']=='registo' || isset($_GET['e']) && $_GET['e']=='true') 
      {require_once "views/registo.php"; 
     } 
     else{require_once "views/login.php";} 



     ?> 

    </div> 

(REQUIRE_ONCE)registo.php

<center> 
<div class="box_css"> 
<form class = "form-signin" role = "form" action = "register.php" method = "post" style="max-width:50%"> 
      <h4 class = "form-signin-heading">Registar um Novo Utilizador</h4> 
      <input type = "text" class = "form-control" name = "reg_username" placeholder = "Nome de Utilizador" required autofocus></br> 
      <input type = "password" class = "form-control" name = "reg_password" placeholder = "Password" required> 
      <button style="margin-top: 15px; margin-bottom: 15px;" class = "btn btn-lg btn-primary btn-block hvr-grow-shadow" type = "submit" name = "registo">Registar</button> 
     </form> 
     <a href="index.php" style="max-width:50%;" class="btn btn-lg btn-primary btn-block hvr-icon-back">Voltar</a> 

     </div> 

     </center> 
+1

首先,这是错误的'index.php?p = registo?success = 1'。只有第一个问号被视为传入参数的指示。之后的所有其他问号都被视为字面问号 – JapanGuy

回答

0
You Should be pass parameters Like this: 
Before : header("location: index.php?p=registo?success=1"); 
     header("location: index.php?p=registo?e=true"); 
After : header("location: index.php?p=registo&success=1"); 
     header("location: index.php&p=registoe=true");