Sample List (PHP)
Date: 08/21/2009
Program Name: Sample List (PHP)
Description: The purpose of this PHP program is get records of a database, and show only the last 30 items.
<?php session_start(); include ('request_processor.php'); include ('********.php'); include ('menu.php'); include ('head.php'); //were going to check of the were able to connect to the database. If we can not then print a message that we can not $result = con_test(); if (!$result) { echo ('Connection status: <b><span style="color:red">error</span></b> <br /> <p>Please check to see if the MySQL database service is on.'); exit(0); } else { if ($_SESSION['login'] == '') //indicating that if the variable is not set than the { //print the login page print ("<table align=\"center\" border=\"0\"><form action=\"login.php\" method=\"post\"><table border=\"0\" align=\"center\">"); print ("<tr><td>User Name:</td><td><input type=\"text\" size=\"30\" maxlength=\"28\" name=\"Name\" /></td>"); print ("</tr><tr><td>Password:</td><td><input type=\"text\" size=\"30\" maxlength=\"28\" name=\"pass\" /></td>"); print ("<tr><td align=\"center\" colspan=\"2\"><input type=\"submit\" value=\"Login\" />"); print ("<input type=\"button\" value=\"Lost Password\" /></td></tr></table></form></body></html>"); $_SESSION['login'] = 'check'; exit(0); } elseif($_SESSION['login'] == 'check') { //Will start first by openning a connection to mysql $connection = con(); //get the name and password from the login page $name = $_POST["Name"]; $pass = $_POST["pass"]; //Create the query command for MySQL $query = "select * from users where UserName = '$name' and password = '$pass'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); if (!mysql_fetch_object($result)) { $_SESSION['login'] = ''; print ("I am sorry but the username or password does not match!<br /><a href=\"/portfilo/login.php\"><td>Go Back</a>"); exit(0); } else { $_SESSION['login'] = 'ja'; head(); //Create the html headers styles(); //Then the styles menu(); //Menu option print ("This is a sample programming Work."); } // close connection mysql_close($connection); } elseif ($_SESSION['login'] == 'ja') { head(); //Create the html headers styles(); //Then the styles menu(); //Menu option print ("This is a sample programming Work."); } // Session cleanup session_destroy(); } ?>