404 错误本地主机 xampp
404 error localhost xampp
嗨!
我正在一个网站上工作,但此刻我被卡住了!
当我按下提交按钮时,我将被重定向到
Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.29 (Win32) OpenSSL/1.1.0g PHP/7.2.0
我曾尝试更改我的 XAMPP 端口,但它也不起作用。我也用谷歌搜索过,但没有结果。
我认为这与我的 header 变量有关。
但我还是初学者,所以还看不出错误。
我该怎么办?
我的代码 -->
//Database connect
$host = "localhost"; //Database host --------------------
$user = "root"; //User in the database --------------------
$password = ""; //The password to the database --------------------
$database = "hjaelpsom"; //The specific database --------------------
//Database connect validation --------------------
$connect = mysqli_connect($host, $user, $password, $database);
if(!$connect){
echo "Kunne ikke tilslutte til vores database! Prøv igen senere!";
header("Location: ../HTML-opret-ung.php");
} else {
//Inserting the input to variables
$name = $_POST["name"];
$mail = $_POST["email"];
$mailConfirm = $_POST["emailConfirm"];
$age = $_POST["age"];
$password = $_POST["password"];
$passwordConfirm = $_POST["passwordConfirm"];
$agree = $_POST["agree"];
$submit = $_POST["submit"];
//Validation of the user input --------------------
//If the submit button is clicked --------------------
if(isset($_POST['submit'])){
//Check if all fields are filled --------------------
if(empty($name) || empty($mail) || empty($mailConfirm) || empty($age) || empty($password) || empty($passwordConfirm) || empty($agree)){
echo "Du skal udfylde ALLE felterne!";
header("Location: HTML-opret-ung.php");
exit;
} else {
//Name --------------------
if(!preg_match("/^[a-åA-Å ]*$/", $name)){
echo "Du skal indtaste et navn ikke $name";
header("Location: HTML-opret-ung.php");
exit;
} else {
//Mails --------------------
if(!filter_var($mail, FILTER_VALIDATE_EMAIL) || !filter_var($mailConfirm, FILTER_VALIDATE_EMAIL)){
echo "Du har indtastet en ugyldig email!";
header("Location: HTML-opret-ung.php");
exit;
} else {
$mailCheck = "SELECT * FROM unge WHERE email='$mail'";
$mailResult = mysqli_query($connect, $mailCheck);
$mailResultCheck = mysqli_num_rows($mailCheckResult);
if($mailResultCheck > 0){
echo "Din email var allerede i brug!";
exit;
} else {
if($mail === $mailConfirm){
echo "Dine emails var ikke ens!";
header("Location: HTML-opret-ung.php");
exit;
} else {
//Age --------------------
if($age < 12 || $age > 17){
echo "Du er enten for ung eller for gammel!";
} else {
//Passwords -------------------- 1:04:32
if(preg_match("/^[a-zA-Z0-9]*$/")){
if($password === $passwordConfirm){
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
//Insert into DB --------------------
$insertSQL = "INSERT INTO unge (Name, Email, Age, Password) VALUES ('$name', '$mail', '$age', '$passwordHash')";
mysqli_query($connect, $insertSQL);
} else {
echo "Dine kodeord skal være ens!";
}
} else {
echo "Dit kodeord skal mindst indeholde: et stort bogstav, et småt bogstav og et tal";
exit();
}
}
}
}
}
}
}
} else {
header("Location: ../HTML-opret-ung.php");
exit();
}
}
404 错误表明文件丢失或您正在重定向到错误的目录。 $_POST["submit"] return 是什么意思?
也尝试完全删除 headers 并查看它是否仍然 return 是什么东西。
删除 headers.
后尝试 var_dump() 或 echo
我自己一直在使用 xampp,当我输入错误时,404 主要与错误的文件路径有关。
../ 表示当前目录之上的目录。
嗨! 我正在一个网站上工作,但此刻我被卡住了! 当我按下提交按钮时,我将被重定向到
Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.
Error 404 localhost Apache/2.4.29 (Win32) OpenSSL/1.1.0g PHP/7.2.0
我曾尝试更改我的 XAMPP 端口,但它也不起作用。我也用谷歌搜索过,但没有结果。
我认为这与我的 header 变量有关。
但我还是初学者,所以还看不出错误。
我该怎么办?
我的代码 -->
//Database connect
$host = "localhost"; //Database host --------------------
$user = "root"; //User in the database --------------------
$password = ""; //The password to the database --------------------
$database = "hjaelpsom"; //The specific database --------------------
//Database connect validation --------------------
$connect = mysqli_connect($host, $user, $password, $database);
if(!$connect){
echo "Kunne ikke tilslutte til vores database! Prøv igen senere!";
header("Location: ../HTML-opret-ung.php");
} else {
//Inserting the input to variables
$name = $_POST["name"];
$mail = $_POST["email"];
$mailConfirm = $_POST["emailConfirm"];
$age = $_POST["age"];
$password = $_POST["password"];
$passwordConfirm = $_POST["passwordConfirm"];
$agree = $_POST["agree"];
$submit = $_POST["submit"];
//Validation of the user input --------------------
//If the submit button is clicked --------------------
if(isset($_POST['submit'])){
//Check if all fields are filled --------------------
if(empty($name) || empty($mail) || empty($mailConfirm) || empty($age) || empty($password) || empty($passwordConfirm) || empty($agree)){
echo "Du skal udfylde ALLE felterne!";
header("Location: HTML-opret-ung.php");
exit;
} else {
//Name --------------------
if(!preg_match("/^[a-åA-Å ]*$/", $name)){
echo "Du skal indtaste et navn ikke $name";
header("Location: HTML-opret-ung.php");
exit;
} else {
//Mails --------------------
if(!filter_var($mail, FILTER_VALIDATE_EMAIL) || !filter_var($mailConfirm, FILTER_VALIDATE_EMAIL)){
echo "Du har indtastet en ugyldig email!";
header("Location: HTML-opret-ung.php");
exit;
} else {
$mailCheck = "SELECT * FROM unge WHERE email='$mail'";
$mailResult = mysqli_query($connect, $mailCheck);
$mailResultCheck = mysqli_num_rows($mailCheckResult);
if($mailResultCheck > 0){
echo "Din email var allerede i brug!";
exit;
} else {
if($mail === $mailConfirm){
echo "Dine emails var ikke ens!";
header("Location: HTML-opret-ung.php");
exit;
} else {
//Age --------------------
if($age < 12 || $age > 17){
echo "Du er enten for ung eller for gammel!";
} else {
//Passwords -------------------- 1:04:32
if(preg_match("/^[a-zA-Z0-9]*$/")){
if($password === $passwordConfirm){
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
//Insert into DB --------------------
$insertSQL = "INSERT INTO unge (Name, Email, Age, Password) VALUES ('$name', '$mail', '$age', '$passwordHash')";
mysqli_query($connect, $insertSQL);
} else {
echo "Dine kodeord skal være ens!";
}
} else {
echo "Dit kodeord skal mindst indeholde: et stort bogstav, et småt bogstav og et tal";
exit();
}
}
}
}
}
}
}
} else {
header("Location: ../HTML-opret-ung.php");
exit();
}
}
404 错误表明文件丢失或您正在重定向到错误的目录。 $_POST["submit"] return 是什么意思? 也尝试完全删除 headers 并查看它是否仍然 return 是什么东西。 删除 headers.
后尝试 var_dump() 或 echo我自己一直在使用 xampp,当我输入错误时,404 主要与错误的文件路径有关。
../ 表示当前目录之上的目录。