Getting 404 Error on Form Submission PHP

epiz_32718968

Getting 404 Error on Form Submission PHP, it’s working fine on localhost but after uploading on InfinityFree, It is giving me 404 error.

Here is my Code

Main file index.php

    <div class="form2">
        <form method="post" onsubmit="getConfirmation()" name="myForm">
            <h2>Form Registration with<br>Validation and Confirm Dialog</h2>
            <p><sup>*</sup> required field</p>
            <div class="formName">
            <label for="fname">Name:</label>
                <input type="text" name="fname" id="fname" placeholder="Type your name.." value="<?php if (isset($_SESSION['name'])) echo $_SESSION['name'] ?>" required>
                <span></span><sup class="sup">*</sup></span>
                <p class="error"><?php
                if (isset($_SESSION['error1'])) {
                echo nl2br($_SESSION['error1']);
                }
                ?>
                <?php unset($_SESSION['error1']); ?>
                </p>
            </div>
                
                <br>
                <div class="formName">
                <label for="email">Email:</label>
                <input type="email" name="email" id="email" placeholder="Type your email.." required value="<?php if (isset($_SESSION['email'])) echo $_SESSION['email']?>"><span></span><sup class="sup">*</sup></span>
                </div>
                <br>

After form submission
functions.php


// Session
session_start();

// MySQL connection
$conn = mysqli_connect("sql1011.epizy.com", "epiz_327183968","HIDDEN BY MOD","epiz_327183968_firstdb");
if ($conn->connection_error) {
    die("Connection failed:" . $conn->connect_error);
}
$_SESSION["ConnSuccess"] = "Success";
header("Location: First.php");  


$//conn = mysqli_connect("server = sql101.epizy.com; port = 3306; user = epiz_32718968; password = HIDDEN BY MOD; database = epiz_32718968_firstdb");

$_nameerr = $_emailerr = $_weberr = $_gendererr = $_checkboxerr = $_commenterr = "";

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (empty($_POST['fname'])) { //This we can also achieve with HTML required attribute directly in form
        $_nameerr = "Please fill name";
        $_SESSION['error1'] = $_nameerr;
        header("Location: First.php");
    } else {
        $_name = trimmydata($_POST['fname']);
        if (!preg_match("/^[a-zA-Z-' ]*$/",$_name)) {
            $_nameerr = "Only Letters and WhiteSpace allowed";
            $_SESSION['error1'] = $_nameerr;
            $_SESSION['name'] = $_name;
            header("Location: First.php");    
        }
    }
    

MySQL

Directory

I don’t understand why after submission of form it gives my 404 error and data not saved in my database.

Please advise

Thanks

Please share your entire index.php file

Welcome to InfinityFree.

What’s the code that runs when the function getConfirmation() runs?

Hi,
I have solved it. The problem was file name in my PHP file which was being executed after form submission. Actually before my homepage file name was first.php which I renamed as index.php after uploading to server but in my code I forgot to rename the file name so the browser was giving 404 error.

I changed this ```
header(“Location: First.php”);

header("Location: index.php");


Now problem solved.
Thanks

OP’s problem was solved and no reply after 7 days time.