Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <body>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "fruitkha_fzdb";
- // Create connection
- if(count($_POST)>0) {
- $conn = new mysqli($servername, $username, $password,$dbname);
- // Check connection
- if ($conn->connect_error)
- {
- die("Connection failed: " . $conn->connect_error);
- }
- echo "Connected successfully";
- $myusername=$_POST['username'];
- $mypassword=$_POST['password'];
- $myemailid=$_POST['emailid'];
- $from_date=$_POST['from_date'];
- $to_date=$_POST['to_date'];
- $no_of_logins=$_POST['no_of_logins'];
- $logged_in=$_POST['logged_in'];
- $sql= "INSERT INTO login (`username`,`password`,`emailid`,`from_date`,`to_date`,`no_of_logins`,`logged_in`)
- VALUES ('$myusername','$mypassword','$myemailid','$from_date','$to_date','$no_of_logins','$logged_in')";
- if (mysqli_query($conn, $sql))
- {
- echo "New record created successfully";
- }
- else
- {
- echo "Error: " . $sql . "<br>" . mysqli_error($conn);
- }
- //$sql2 = "SELECT username, password FROM login where username='$myusername' && password='$mypassword'";
- $sql2 = "SELECT * FROM login";
- //$query1 = $conn->query($sql2);
- $result = mysqli_query($conn,$sql2);
- $message="";
- $count = mysqli_num_rows($result);
- if($count==0) {
- $message = "Invalid Username or Password!";
- } else {
- $message = "You are successfully authenticated!";
- }
- }
- ?>
- <h1 style="color:red;"><b>Customer Database</b></h1>
- <table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" >
- <thead>
- <tr>
- <th>customer id: </th>
- <th>Username: </th>
- <th>Password</th>
- <th>Emailid</th>
- <th>From Date</th>
- <th>To Date</th>
- <th>No of Logins</th>
- <th>No of Logged In</th>
- </tr>
- </thead>
- <tbody>
- <?php
- while( $row = mysqli_fetch_assoc( $result ) )
- {
- echo
- "<tr>
- <td>{$row['id']}</td>
- <td>{$row['username']}</td>
- <td>{$row['password']}</td>
- <td>{$row['emailid']}</td>
- <td>{$row['from_date']}</td>
- <td>{$row['to_date']}</td>
- <td>{$row['no_of_logins']}</td>
- <td>{$row['logged_in']}</td>
- </tr>n";
- }
- ?>
- </tbody>
- </table>
- <?php mysqli_close($conn); ?>
- ?>
- </body>
- </html>
- <html>
- <head>
- </head>
- <title>Login Form</title>
- <body>
- <form method="post" action="insert.php">
- <table border="1">
- <tr>
- <td>User Id:<input type="text" name="username"></td>
- </tr>
- <!--<tr>
- <td>Password:<input type="password" name="password"></td>
- </tr>-->
- <tr>
- <td>
- <input type="Textbox" id="pwbx" name="password" />
- <button OnClick="GetRandom()" type="button">generate</button>
- <script>
- function GetRandom()
- {
- var myElement = document.getElementById("pwbx")
- myElement.value = Math.round(Math.random()*900000)+100000;
- }
- </script>
- </td>
- </tr>
- <tr>
- <td>Email Id:<input type="email" name="emailid"></td>
- </tr>
- <tr>
- <td>From Date:<input type="date" name="from_date"></td>
- </tr>
- <tr>
- <td>To Date:<input type="date" name="to_date"></td>
- </tr>
- <tr>
- <td>No. Of Logins:<input type="number" name="no_of_logins"></td>
- </tr>
- <tr>
- <td>No. Of Logged in:<input type="number" name="logged_in"></td>
- </tr>
- <tr>
- <td><input type="submit" value="Submit"></td>
- </tr>
- </table>
- </form>
- </body>
- </html>
- <?php
- session_start();
- if(isset($_POST['bttLogin']))
- {
- //require 'connect.php';
- $con=mysqli_connect('localhost','root','','fruitkha_fzdb');
- $username=$_POST['username'];
- $password=$_POST['password'];
- $result=mysqli_query($con,'select * from login where username="'.$username.'" and password="'.$password.'"');
- if(mysqli_num_rows($result)==1)
- {
- $_SESSION['username']=$username;
- header('Location:welcome.php');
- }
- else
- {
- echo "Invalid account";
- }
- }
- if(isset($_GET['logout']))
- {
- session_unregister('username');
- }
- ?>
- <form method="post">
- Enter a user id:<input type="text" name="username" />
- enter a password:<input type="password" name="password" />
- <input type="submit" name="bttLogin" value="LOGIN" />
- </form>
- <?php
- session_start();
- echo 'Welcome'.'.....'.$_SESSION['username'];
- echo '<br><a href="form.php?=logout">Logout</a>';
- //echo 'Welcome to my Webpage';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement