Ask Question - Get Answer

6 Ans PHP log in form code download from here

Asked by Birds of the sky (2 Golds) Thursday, 30 Dec 2021, 07:05 AM at (Technology Computer)

Please log in to answer, like and save
0
Save 0

<<< Previous
Log in to Answer Next >>>

Answer(s):

config.php  ( Database Connection and Configuration File )

<?php

if (session_status() == PHP_SESSION_NONE) {
    session_start();
}

$server = "localhost";
$user = "root";
$pass = "";
$dbname = "bpsc";
$conn = mysqli_connect($server, $user, $pass, $dbname);
if ($conn) {
    //echo 'Connected';
}

/* At first Create Table with this Query 
CREATE TABLE `test` (
 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 `name` varchar(255) NOT NULL,
 `password` varchar(255) NOT NULL,
 `dob` date NOT NULL,
 UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1
 * 
 */

Answered by Birds of the sky (2 Golds) Thursday, 30 Dec 2021, 07:08 AM

Please log in to Upvote, Downvote and Report

PHP login form creation is very easy. Just copy and paste this on your IDE (Ex: Netbeans...) and XAMPP , MYSQL etc and get output.

Thanks.  

Answered by Birds of the sky (2 Golds) Thursday, 30 Dec 2021, 07:06 AM

Please log in to Upvote, Downvote and Report

index.php file


<?php

include_once 'config.php';

?>

<html>

    <head>

        <title>

            PHP LOG IN FORM

        </title>

    </head>

    <body>

        

        <a href="index.php"> Add Data </a> <br>

        <a href="login.php"> Log In Data </a> <br>

        <a href="logout.php"> Log Out </a> <br>

         

        

        <h2> Add Data into Database </h2>

        <form method="POST" action="action.php" enctype="multipart/form-data">

            <input type="text" name = "name" placeholder="Enter Name"/>

            <input type="password" name = "password" placeholder="Enter Password"/>

            <input type="date" name="dob"/>

            <input type="submit" name="submit" value="Add Data"/>

        </form>


        <br>

        <br>

    </body>

</html>

<?php

?>

Answered by Birds of the sky (2 Golds) Thursday, 30 Dec 2021, 07:09 AM

Please log in to Upvote, Downvote and Report

action.php (Data is inserted by this page)

<?php

include_once 'config.php';

?>

<a href="index.php"> Add Data </a> <br>

<a href="login.php"> Log In Data </a> <br>

<a href="logout.php"> Log Out </a> <br>

<?php

if (isset($_POST['submit']) & !empty($_POST['submit'])) {

    $sql = "INSERT INTO test(name, password, dob) VALUES('$_POST[name]', '$_POST[password]', '$_POST[dob]')";

    if (mysqli_query($conn, $sql)) {

        echo 'Data Inserted Successfully! ';

    }

}

Answered by Birds of the sky (2 Golds) Thursday, 30 Dec 2021, 07:09 AM

Please log in to Upvote, Downvote and Report

login.php

<?php
include_once 'config.php';
?>
<a href="index.php"> Add Data </a> <br>
<a href="login.php"> Log In Data </a> <br>
<a href="logout.php"> Log Out </a> <br>
<?php
if (isset($_POST['submit']) & !empty($_POST['submit'])) {
    $sql = "SELECT * FROM test WHERE name = '$_POST[name]' AND dob = '$_POST[dob]'";
    $result = mysqli_query($conn, $sql);
    if ($result) {
        if ($row = mysqli_fetch_assoc($result) > 0) {
            $name = $row['name'];
            $pass = $row['password'];
            $dob = $row['dob'];

            $_SESSION['logged'] = 'yes';

            echo 'Logged in successfully!';
            echo $name;
            echo $pass;
            echo $dob;
        } else {
            echo 'Name, Password, DOB not Matched! ';
        }
    }
}
?>
<h2> Log In Database </h2>
<form method="POST" action="login.php" enctype="multipart/form-data">
    <input type="text" name = "name" placeholder="Enter Name"/>
    <input type="password" name = "password" placeholder="Enter Password"/>
    <input type="date" name="dob"/>
    <input type="submit" name="submit" value="Log In"/>
</form>
<?php

Answered by Birds of the sky (2 Golds) Thursday, 30 Dec 2021, 07:10 AM

Please log in to Upvote, Downvote and Report

logout.php file


<?php

include_once 'config.php';

?>

<a href="index.php"> Add Data </a> <br>

<a href="login.php"> Log In Data </a> <br>

<a href="logout.php"> Log Out </a> <br>

<?php

if(session_destroy())

{

    echo 'Logged Out Successfully! ';

}


?>


Answered by Birds of the sky (2 Golds) Thursday, 30 Dec 2021, 07:11 AM

Please log in to Upvote, Downvote and Report
           

Related Q/A:

1 Ans How to send Javascript .js file in Gmail or other way?

2 Ans A Powerful Gaming Laptop Configuration Module

2 Ans How to unblock a phone number on Samsung mobile phone?

1 Ans What can be done with Python?

1 Ans What does 'bug' mean in the language of computers / programming?

1 Ans Top 10 favorite keyboard shortcuts

3 Ans How to speed Up My Sql Query and Database

1 Ans What is a computer network?

1 Ans Facebook Shortcut tips details

1 Ans How to become a computer hacker?