简体   繁体   中英

404 error localhost xampp

Hi! I'm working on a website, but at the moment I'm stuck! When I press the Submit button, I will be redirected to

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

I have tried to change my XAMPP ports, but it does not work either. I have also googled it, but without results.

I think it has something to do with my header variable.

But i am stil a beginner so can not see mistakes yet.

What should I do?

My code -->

//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();
    }

}

The 404 error shows that the file is either missing or you are redirecting to the wrong directory. What does the $_POST["submit"] return? Also try to remove the headers completely and see if it still returns something. Try a var_dump() or echo after removing the headers.

I have been using xampp myself and mainly 404 has to do with the wrong filepath when I give a wrong input.

The ../ means a directory above the current directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM