-- -- Table structure for table `user_registration` -- CREATE TABLE `user_registration` ( `user_id` INT(11) NOT NULL, `first_name` VARCHAR(100) NOT NULL, `last_name` VARCHAR(100) NOT NULL, `user_name` VARCHAR(100) NOT NULL, `password` VARCHAR(100) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
<?php $conn = new PDO('mysql:host=localhost; dbname=registration_pdo','root', ''); ?>
<?php include('connection.php'); $user_name = $_POST['user_name']; $password = $_POST['password']; $query = $conn->query("Select * from user_registration where user_name = '$user_name' and password ='$password' "); $count = $query->rowcount(); $row = $query->fetch(); if ($count > 0){ $_SESSION['id'] = $row['user_id']; } else { ?> <script> alert("Incorrect Details. Check your User Name or Password.") window.location="index.php"; </script> <?php } ?>
<?php ?>
<?php include ('connection.php'); ?> <!DOCTYPE html> <html> <head> <title>How To Create User Login Page In PHP/MySQL Using PDO Query</title> <link rel="stylesheet" type="text/css" href="styles.css" /> </head> <body> <?php } $session_id = $_SESSION['id']; $session_query = $conn->query("select * from user_registration where user_id = '$session_id'"); $user_row = $session_query->fetch(); ?> <table border="0" cellpadding="10" cellspacing="1" width="100%" class="tblLogin"> <tr class="tableheader"> <td align="center">Home</td> </tr> <tr class="tablerow"> <td align="center"> <p class="blink_text">Welcome User!!!</p> <?php echo $user_row['first_name']." ".$user_row['last_name']; ?> </td> </tr> <tr class="tableheader"> <td align="center"> Click here to <a href="log_out_query.php"> Logout </a> </td> </tr> </table> </body> </html>
body { width:500px; margin:auto; } h2 { color:red; font-family:cursive; text-align:center; } a { text-decoration:none; color:black; } a:hover { color:red; } .tableheader { background-color: aliceblue; color:blue; font-weight:bold; font-size:large; } .tablerow { background-color: whitesmoke; color:blue; font-weight:bold; font-size:18px; } #message { color: white; border: red 1px solid; background: red; padding:20px; font-size:18px; font-weight:bold; margin-top: 31px; border-radius:4px; width: 305px; } .tblLogin{ margin : auto; border:blue 3px solid; } .textbox_detail { font-size:18px; text-indent:5px; background:azure; border:blue 1px solid; border-radius:4px; cursor:pointer; } .btn_submit { font-size:18px; width:100px; border:blue 1px solid; background:azure; color:blue; cursor:pointer; } .blink_text { -webkit-animation-name: blinker; -webkit-animation-duration: 1s; -webkit-animation-timing-function: linear; -webkit-animation-iteration-count: infinite; -moz-animation-name: blinker; -moz-animation-duration: 1s; -moz-animation-timing-function: linear; -moz-animation-iteration-count: infinite; animation-name: blinker; animation-duration: 1s; animation-timing-function: linear; animation-iteration-count: infinite; color:red; font-size:large; } @-moz-keyframes blinker { 0% { opacity: 1.0; } 50% { opacity: 0.0; } 100% { opacity: 1.0; } } @-webkit-keyframes blinker { 0% { opacity: 1.0; } 50% { opacity: 0.0; } 100% { opacity: 1.0; } } @keyframes blinker { 0% { opacity: 1.0; } 50% { opacity: 0.0; } 100% { opacity: 1.0; } }