user10692760
user10692760

Reputation:

When form submitted action does not execute

I am making a basic registration form and my code is not working I tried problem-solving but I do not see any issues in my code. When the user submits the form the page does not go to register.php

Here is my connect.php code:

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "WifiP";

/* Attempt to connect to MySQL database */
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if($conn === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>

Here is my header.php code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>WifiP | Home</title>
    <link rel="stylesheet" type="text/css" href="main.css">
    <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
</head>
<body>
    <ul>
    <li><a href="index.php">Home</a></li>
    <li><a href="wifi_page.php">Wifi</a></li>
    <li><a href="login_page.php">Login</a></li>
    </ul>

Here is my footer.php code:

</body>
</html>

Here is my register.php code:

<?php 

require_once 'connect.php' ;

$sql = "INSERT INTO users (email, password)
        VALUES ('".$_POST["email"]."','".$_POST["password"]."')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

?>

Here is my register_page.php code:

<?php require_once 'header.php' ?>

<center>
    <h1 class='pageTitle'>Register</h1>
    <a href="register_page.php" class='registerLink'> Or Login</a><br>
    <form action="register.php" method="post">
        <input type="text" name="email" placeholder="Email"> <br>
        <input type="password" name="password" placeholder="Password"><br>
        <input type="password" name="rPassword" placeholder="Retype Password"><br>
        <input type="button" value="Submit">
    </form>
</center>

<?php require_once 'footer.php' ?>

Upvotes: 0

Views: 589

Answers (1)

amin msh
amin msh

Reputation: 474

The HTML element defines a form that is used to collect user input and after user insert that data need to submit the form to send that inserted data to action path.

To submitting a form there are some possible ways but according to your question you want to send data to 'register.php' by clicking the button you defined.

Form elements are different types of input elements, like text fields, checkboxes, radio buttons, submit buttons, and more.

In this case for submission the form you need a submit button that type should be "submit" not "button"

try change your register page like below

        <input type="submit" value="Submit">

please according to the input type that it is "submit" not "button"

now by clicking the submit button your form data will send to action path.

Upvotes: 2

Related Questions