Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php $title = "David Monopoli's INTN2201 Lab 8";
- $date = "March 31st, 2011";
- $filename = "lab8.php";
- $banner = "David Monopoli's INTN2201 - Lab 8";
- $description = "This is lab8, demonstrating how to store logins in a database and use them effectively within a form.";
- include 'header.php'; ?>
- <?php include 'navbar.php';
- include 'functions.php'; ?>
- <?php
- $conn=db_connect();
- $message = "";
- $results = "";
- if($_SERVER["REQUEST_METHOD"] == "GET"){
- //default mode when the page loads the first time
- //can be used to make decisions and initialize variables
- $username="";
- $pass="";
- }
- else if($_SERVER["REQUEST_METHOD"] == "POST"){
- //the page got here from submitting the form, let's try to process
- $username = trim($_POST["username"]); //the name of the input box on the form, white-space removed
- $pass = trim($_POST["password"]);
- //issets were here
- $sql = "SELECT username_id, password, first_name, last_name, email_addr, last_access
- FROM users
- WHERE username_id= '".$username."' AND
- password= '".$pass."'";;
- $results = pg_query($conn, $sql);
- if(pg_num_rows($results)){ //not zero means something was found
- //user found, use pg_fetch_resultto pull user specific info to display
- $first=pg_fetch_result($results, 0, "first_name");
- $last=pg_fetch_result($results, 0, "last_name");
- $email=pg_fetch_result($results, 0, "email_addr");
- $lastaccess=pg_fetch_result($results, 0, "last_access");
- $message="Welcome back " .$first . $last. " Records show that your email is: " . $email . ", you last accessed the account on: " .$lastaccess;
- }else{
- //user not found, check for just username id
- $sql= "SELECT * FROM users WHERE login_id= '".$username."'";
- $results = pg_query($conn, $sql);
- $message="Invalid password, please try again.";
- if(!pg_num_rows($results)){ //user not found, empty $username to unstickit
- $username = ""; //when echo’’edin the form
- $message= "Username not found, please try again.";
- }
- }
- }
- ?>
- <h3><?php echo $message;?></h3>
- <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
- <table border="0">
- <tr>
- <td><strong>Login ID</strong>
- </td>
- <td><input type="text" name="login" value="<?php echo $login; ?>" size="15" /><br/>
- </td>
- </tr>
- <tr>
- <td><strong>
- Password
- </strong>
- </td>
- <td>
- <input type="password" name="password" value="<?php echo $pass; ?>" size="15" /><br/>
- </td>
- </tr>
- <tr>
- <td>
- <input type="reset" value="Clear" />
- </td>
- <td>
- <input type="submit" value="Login" />
- </td>
- </tr></table>
- </form>
- <br/>
- <a href="SQL/lab8_users.sql">Lab 8 Users Script</a>
- <br/>
- <?php include "footer.php";?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement