-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>
首先,這是錯誤的'index.php?p = registo?success = 1'。只有第一個問號被視爲傳入參數的指示。之後的所有其他問號都被視爲字面問號 – JapanGuy