PHP第二个标签无法正常工作,怎么回事?

时间:2017-04-15 01:53:51

标签: php tags

当我尝试注册用户名已存在的用户时,它应该REQUIRE_ONCE(" registo.php")而不是它转到我的login.php,标题位置重定向到&# 34;?registo.php p =雷吉斯托E =真" ,所以问题出在" index.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 个答案:

答案 0 :(得分: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");