PHP: Library management system

This is an overview of a Library Management system build using PHP. The basic functionalities include

  • adding Bookcase such as ‘bedside bookcase’ or ‘hallway bookcase’, with shelf count and capacity
  • adding books to the bookcase
  • deleting Bookcase (puts the books to the heap)
  • Your profile info

The problem statement can be downloaded here: LMS_Question

[wpi_designer_button text=’Download’ link=’https://github.com/arjunsk/php-library-management-system’ style_id=’48’ icon=’github’ target=’_blank’]

NUTSHELL :-

1 . MYSQL connectivity:

	$conn = mysqli_connect('host', 'username', 'password', 'database'); 
	if (!$conn) {	
		//if mysql connection fails
		die();
	}
	$query = "CREATE DATABASE IF NOT EXISTS library";
	if(mysqli_query($conn, $query)){
		// mysql query succesfully executed.		
	}

2. PHP POST usage

<form method="post" action="">
if( isset($_POST["post_variable"])   )
{
	  if( !empty($_POST["post_variable"]) )
	  {  
              $variable_name=$_POST["post_variable"];

3. Cookie usage

		if (isset($_COOKIE['loggedin']) && $_COOKIE['loggedin'] == true) {
			// if user not logged in
                 }
setcookie("loggedin", 1, time()+3600);  /* expire in 1 hour */
setcookie("username", $email, time()+3600);  /* expire in 1 hour */
<?php
//logout
if (isset($_COOKIE['loggedin'])) {
    unset($_COOKIE['username']);
    unset($_COOKIE['loggedin']);
	setcookie('loggedin', '', time()-300); 
	setcookie('username', '', time()-300); 	
} 
echo "<script>window.open('index.php','_self')</script>";
?>

4. Password MD5

$passMD5 = md5($pass);

5. USER LOGIN SECURITY

	// checking the user
	if(isset($_POST['login'])){
	$email = mysqli_real_escape_string($conn,$_POST['email']);
	$pass = mysqli_real_escape_string($conn,$_POST['pass']);
	$MD5pass=  md5($pass);
	$sel_user = "select * from users where user_email='$email' AND user_pass='$MD5pass'";
	$run_user = mysqli_query($conn, $sel_user);
	$check_user = mysqli_num_rows($run_user);
	if($check_user>0){
		setcookie("loggedin", 1, time()+3600);  /* expire in 1 hour */
		setcookie("username", $email, time()+3600);  /* expire in 1 hour */
		echo "<script>window.open('profile.php','_self')</script>";
	}

6. Filling Tables in PHP

<!-- Table for Bookcase -->
						<form method="post"  action="">	  
						<table class="hovertable">
							<tr>
								<th>Bookcase Name</th><th>Shelf Count</th><th>Shelf Capacity</th><th>   </th>
							</tr>

						<?php
						//Dynamically filling Data into the Table Bookcase
						$result = mysqli_query($conn,  "SELECT * FROM   bookcases  WHERE  user_email = '$username' " );
						if (!$result) {
							echo "Could not successfully run query ($sql) from DB: " . mysql_error();
							exit;
						}
						if (!mysqli_num_rows($result)) {
							echo "No rows found";
						}
						else{
							while ($row = mysqli_fetch_assoc($result)) {
							$a= $row["bookcase"];
							$b= $row["shelf_count"];
							$c= $row["shelf_cap"];
							
							echo " <tr onmouseover=\"this.style.backgroundColor='#ffff66';\" onmouseout=\"this.style.backgroundColor='#d4e3e5';\"> ";
							echo "<td>$a</td>";
							echo "<td>$b</td>";
							echo "<td>$c</td>";
							echo "<td><input name='del' type=\"radio\" value=\" $a \"></td>";
							echo "</tr>";
							}
						}
						?>
						</table>
						<input type="submit" value="Delete BookCase" name="DELBOOKCASE" />
						</form>

7.Filling combo box dynamically

	 <select  name="D1" style="width: 142px"  >
										 <?php
											//Dynamically filling the combo box  with Bookcases
											$result = mysqli_query($conn,  "SELECT * FROM   bookcases  WHERE  user_email = '$username' " );
											if ($result  && mysqli_num_rows($result) ) {
												while ($row = mysqli_fetch_assoc($result)) {
													$b= $row["bookcase"];
													$c= $row["shelf_count"];
													for($i=1;$i<=$c;$i++){
														echo " <option value=\"$b-$i\">$b , Shelf $i </option> ";
													}
												}
										}
										?>

LEVEL 1 [ Basics ] :-

  1.  CONFIG PAGE

This file is included inside every php page. Stores the database authentication details.

<?php  
	//Checks if the Database is Configured or Not
	//Removes the error reporting
	error_reporting(E_ERROR);
	$conn = mysqli_connect('localhost', 'root', '', 'library'); 
	if (!$conn) {	
		echo "Your Database is not Configures Yet.  Click Here to ";
		echo "<a href='setup.php'>Configure</a>";
		die();
	}
?>

2.   SETUP PAGE

This page creates tables and saves the database authentication details .

setup

<html>
<head>

</head>
<body>
  <form method="post" action="">
       Host<input type="text" name="host">
       Username<input type="text" name="username">
       Password <input type="password" name="password">
       <input type="submit" value="Go">
  </form>
</body>
</html>






<?php

//Removes the error reporting
error_reporting(E_ERROR);

if( isset($_POST["host"]) && isset($_POST["username"])  )
{
	  if(!empty($_POST["host"]) &&  !empty($_POST["username"])    )
	  {
		  

		  
		$host=$_POST["host"];
		$username=$_POST["username"];
		$password=$_POST["password"];
		
		
		$conn = mysqli_connect("$host", "$username", "$password") ; 

		if (!$conn) {
				echo "Something Went Wrong! Try Again. ";
				die();
		}
		
		$query = "CREATE DATABASE IF NOT EXISTS library";
			
			if(mysqli_query($conn, $query)){
				
				// change the mysql password to ""
				$query2="SET PASSWORD FOR 'root'@'localhost' = PASSWORD('') ";
				mysqli_query($conn, $query2);
				mysqli_close($conn);
				
				$conn = mysqli_connect("localhost", "root", "","library") ;
				
				
				
				// sq1 to create table bookcase
				$sql = "CREATE TABLE IF NOT EXISTS `bookcases` (
						  `user_email` varchar(50) NOT NULL,
						  `bookcase` varchar(50) NOT NULL,
						  `shelf_count` int(5) NOT NULL,
						  `shelf_cap` int(5) NOT NULL
						) ENGINE=InnoDB DEFAULT CHARSET=latin1;";

				mysqli_query($conn, $sql);
				
					
				// sq2 to create table books
				$sq2 = "CREATE TABLE IF NOT EXISTS `books` (
					  `user_email` varchar(20) NOT NULL,
					  `bookcase` varchar(20) NOT NULL,
					  `shelf_id` int(5) NOT NULL,
					  `title` varchar(20) NOT NULL,
					  `author` varchar(20) NOT NULL,
					  `gener` varchar(20) NOT NULL,
					  `isbn` varchar(20) NOT NULL,
					  `price` int(5) NOT NULL
					) ENGINE=InnoDB DEFAULT CHARSET=latin1;";

				mysqli_query($conn, $sq2);
				
				
				// sq3 to create table users
				$sq3 = "CREATE TABLE IF NOT EXISTS `users` (
					  `user_id` int(3) unsigned zerofill NOT NULL AUTO_INCREMENT,
					  `user_email` varchar(20) DEFAULT NULL,
					  `user_pass` varchar(50) DEFAULT NULL,
					  PRIMARY KEY (`user_id`)
					) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;";

				mysqli_query($conn, $sq3);
				
				echo "<script>window.open('index.php','_self')</script>";
		
				
			} 
			else{
				die("Connection failed: " . mysqli_connect_error());
			}

	}
}

?>

3.  INDEX PAGE (ie login/register page)

This page opens first when the site is loaded.

login/register

<?php 
include 'config.php';


		if (isset($_COOKIE['loggedin']) && $_COOKIE['loggedin'] == true) {
			echo "<script>window.open('profile.php','_self')</script>";
		}
		
    	if (isSet($_POST['reg']) && isSet($_POST['user']) && isSet($_POST['pass']) && $_POST['user'] != '' && $_POST['pass'] != '') {
    		$pass = $_POST['pass'];
    		$passMD5 = md5($pass);
    		$user = $_POST['user'];
    		$q = mysqli_query($conn, "SELECT * FROM users WHERE user_email='$user'"  ) ;
    		if (mysqli_num_rows($q) ){
    			echo '<script language="javascript">';
				echo 'alert("User Id Already Taken!")';
				echo '</script>';
				
    		}else{
    			$qq = mysqli_query($conn, "INSERT INTO users VALUES ('', '$user', '$passMD5')");
    			if ($qq) {
    				echo '<script language="javascript">';
					echo 'alert("Successfully Registered!")';
					echo '</script>';
    			}else{
    				echo '<script language="javascript">';
					echo 'alert("Something Went Wrong!")';
					echo '</script>';
				}			
    	}
	}
    ?>
	
	


<html >
  <head>
    <meta charset="UTF-8">
    <title>Login/Sign-In</title>
    <link rel="stylesheet" href="css/normalize.css">
    <link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css'>
    <link rel="stylesheet" href="css/style.css">
  </head>

  
  
  
  <body>

    <div class="logmod">
  <div class="logmod__wrapper">

    <div class="logmod__container">
      <ul class="logmod__tabs">
        <li data-tabtar="lgm-2"><a href="#">Login</a></li>
        <li data-tabtar="lgm-1"><a href="#">Sign Up</a></li>
      </ul>
      <div class="logmod__tab-wrapper">
      <div class="logmod__tab lgm-1">
        <div class="logmod__heading">
          <span class="logmod__heading-subtitle">Enter your personal details <strong>to create an acount</strong></span>
        </div>
        <div class="logmod__form">
		
		
		
          <form method="post" accept-charset="utf-8" class="simform" action="">
            <div class="sminputs">
              <div class="input full">
                <label class="string optional" for="user-name">Email*</label>
                <input name="user" class="string optional" maxlength="255" id="user-email" placeholder="Email" type="email" size="50" />
              </div>
            </div>
            <div class="sminputs">
              <div class="input string optional">
                <label class="string optional" for="user-pw">Password *</label>
                <input name="pass" class="string optional" maxlength="255" id="user-pw" placeholder="Password" type="text" size="50" />
              </div>
              <div class="input string optional">
                <label class="string optional" for="user-pw-repeat">Repeat password *</label>
                <input name="RepeatPass" class="string optional" maxlength="255" id="user-pw-repeat" placeholder="Repeat password" type="text" size="50" />
              </div>
            </div>
            <div class="simform__actions">
              <input class="sumbit" name="reg" type="submit" value="Create Account" />
             </div> 
			 
			 <span class="simform__actions-sidetext"> <a class="special" href="#" target="_blank" role="link">
			 </a></span>  	 
          </form>
		  
		  
		  
		  
		  
		  
        </div> 
      </div>
      <div class="logmod__tab lgm-2">
        <div class="logmod__heading">
          <span class="logmod__heading-subtitle">Enter your email and password <strong>to sign in</strong></span>
        </div> 
        <div class="logmod__form">
		
		
		
		
          <form accept-charset="utf-8"  class="simform" method="post" action="login_script.php"  >
            <div class="sminputs">
              <div class="input full">
                <label class="string optional" for="user-name">Email*</label>
                <input name="email" class="string optional" maxlength="255" id="user-email" placeholder="Email" type="email" size="50" />
              </div>
            </div>
            <div class="sminputs">
              <div class="input full">
                <label class="string optional" for="user-pw">Password *</label>
                <input name="pass" class="string optional" maxlength="255" id="user-pw" placeholder="Password" type="password" size="50" />
                						<span class="hide-password">Show</span>
              </div>
            </div>
            <div class="simform__actions">
              <input name="login" class="sumbit" name="commit" type="submit" value="Log In" />
              <span class="simform__actions-sidetext"></span>
            </div> 
          </form>
		  


		  
		  
        </div> 
            </div>
      </div>
    </div>
  </div>
</div>
    http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js

        http://js/index.js

    
    
    
  </body>
</html>

4.   LOGIN SCRIPT 

Validates the user login details , given from the login page.

<?php
include 'config.php';

	// establishing the MySQLi connection
	if (mysqli_connect_errno()){
		echo "MySQLi Connection was not established: " . mysqli_connect_error();
	}

	// checking the user
	if(isset($_POST['login'])){
	$email = mysqli_real_escape_string($conn,$_POST['email']);
	$pass = mysqli_real_escape_string($conn,$_POST['pass']);
	$MD5pass=  md5($pass);
	$sel_user = "select * from users where user_email='$email' AND user_pass='$MD5pass'";
	$run_user = mysqli_query($conn, $sel_user);
	$check_user = mysqli_num_rows($run_user);
	if($check_user>0){
		setcookie("loggedin", 1, time()+3600);  /* expire in 1 hour */
		setcookie("username", $email, time()+3600);  /* expire in 1 hour */
		echo "<script>window.open('profile.php','_self')</script>";
	}
	else {
		echo "<script>alert('Email or password is not correct, try again!')</script>";
		echo "<script>window.open('index.php','_self')</script>";
	}
}
?>

5.   PROFILE PAGE

The main page for entering the book details, viewing profile etc.

main page

<?php
include 'config.php';

//redirects to login page if user is not yet logged in
if (!isset($_COOKIE['loggedin']) && $_COOKIE['loggedin'] == false) {
    echo "<script>window.open('index.php','_self')</script>";
	exit;
} 

	//COOKIE username is global here
	$username=$_COOKIE['username'];
	
?>



<?php
//For Adding Bookcases

if (isSet($_POST['ADDBCASE']) && 
	isSet($_POST['BOOKCASE']) && isSet($_POST['SHELFCOUNT'])  && isSet($_POST['SHELFCAP'])
	&& $_POST['BOOKCASE'] != ''  && $_POST['SHELFCOUNT'] != ''   && $_POST['SHELFCAP'] != '') {

	$username=$_COOKIE['username'];
	$bookcase=$_POST['BOOKCASE'];
	$shelf_count=$_POST['SHELFCOUNT'];
	$shelf_cap=$_POST['SHELFCAP'];

	$sql = "INSERT INTO bookcases  (user_email, bookcase, shelf_count,shelf_cap)VALUES ('$username', '$bookcase', '$shelf_count','$shelf_cap')";

	if (mysqli_query($conn, $sql)) {echo "New record created successfully";} 
	else {echo "Error: " . $sql . "<br>" . mysqli_error($conn);}
 }
?>



<?php
//for adding books

if (isSet($_POST['ADDBOOK']) && isSet($_POST['D1']) && isSet($_POST['D2']) && isSet($_POST['D3']) && isSet($_POST['D4']) && isSet($_POST['D5'])  && isSet($_POST['D6']) )
{ 
	
	if( $_POST['D2'] != ''   && $_POST['D3'] != '' && $_POST['D4'] != ''  && $_POST['D5'] != ''   && $_POST['D6'] != ''  &&
		$_POST['D2'] != 'Title'  && $_POST['D3'] != 'Author'   && $_POST['D4'] != 'Genre' && $_POST['D5'] != 'ISBN'  && $_POST['D6'] != 0  ) {

		list($bookcase, $shelf_id) = explode("-", $_POST['D1'], 2);
		$title=$_POST['D2'];
		$author=$_POST['D3'];
		$gener=$_POST['D4'];
		$isbn=$_POST['D5'];
		$price=$_POST['D6'];
					
			
	
			//For checking if the shelf is full or not
			$q1 = mysqli_query($conn, "SELECT * FROM books  WHERE user_email=\"$username\" and bookcase=\"$bookcase\" and shelf_id=\"$shelf_id\"  "  ) ;
    		$count=mysqli_num_rows($q1) ;

			
			$q2 = mysqli_query($conn,  "SELECT shelf_cap FROM   bookcases  WHERE  user_email=\"$username\" and bookcase=\"$bookcase\" "  );
			$row = mysqli_fetch_assoc($q2) ;
			$limit=$row['shelf_cap'];
			
			if($count>=$limit){
				echo '<script language="javascript">';
				echo 'alert("This Shelf is full! Try other Shelfs.")';
				echo '</script>';
			}  //end of checking if the shelf is full
			else{

					$sql2 = "INSERT INTO books  (user_email,bookcase, shelf_id, title,author,gener,isbn,price)VALUES ('$username','$bookcase', '$shelf_id', '$title','$author','$gener', '$isbn', '$price') ";

					if (mysqli_query($conn, $sql2)) {echo "New record created successfully";} 
					else {echo "Error: " . $sql2 . "<br>" . mysqli_error($conn);}
			
			}
	}else{//echo 'POST';}
}else {//echo 'ISSET';}
?>


<?php
//for deleting bookcase
if (isSet($_POST['DELBOOKCASE']) && isSet($_POST['del'])&& $_POST['del'] != '' ) {


		$bookcase=trim($_POST['del']);
		
		$username=$_COOKIE['username'];
		
		$sql3 = "UPDATE  books SET bookcase=\"heap\" where  user_email=\"$username\" AND bookcase=\"$bookcase\" ";
		if (mysqli_query($conn, $sql3)) {} 
		else {echo "Error: " . $sql3 . "<br>" . mysqli_error($conn);}
		
		$sql4="DELETE FROM bookcases WHERE user_email=\"$username\" AND bookcase=\"$bookcase\" ";
		echo $sql4;
		if (mysqli_query($conn, $sql4)) {} 
		else {echo "Error: " . $sql4 . "<br>" . mysqli_error($conn);}		
 }
?>






<html lang="en-US">
<head>
  <meta charset="utf-8">
  <meta http-equiv="Content-Type" content="text/html">
  <title>User Profile</title>
  <link rel="stylesheet" type="text/css" media="all" href="css/styles_profile.css">
  http://js/jquery-1.10.2.min.js
</head>

<body>
  <div id="topbar">
  <a  href="logout.php"  style="float: right;margin-right:30px;">Log Out</a>
  </div>
  
  <div id="w">
    <div id="content" class="clearfix">
      <h1> User Profile </h1>
      <nav id="profiletabs">
        <ul class="clearfix">
          <li><a href="#activity">Bookcases</a></li>
          <li><a href="#friends">Heaps</a></li>
          <li><a href="#settings">Profile</a></li>
        </ul>
      </nav>
      
	  
<!-- BookCases -->	  
<section id="activity">
	  
	  
	  
<div class="title_box" >
<div id="title"><b>Add BookCase <b></div>
<div id="content">
						
						<!-- Form for Adding Bookcases -->
						<table width="50%" border="1" cellpadding="1" cellspacing="1" class="test">
						  <tr>
							<td>Bookcase Name</td>
							<td>Shelf Count</td>
							<td>Shelf Capacity</td>
						  </tr>		  
						  <form method="post"  action="">
						  <tr>
							<td><input type="text" class="txtbox" value="" name="BOOKCASE" /></td>
							<td><input type="text" class="txtbox" value="" name="SHELFCOUNT" /></td>
							<td><input type="text" class="txtbox" value="" name="SHELFCAP"/></td>
							<td><input type="submit" value="Add" name="ADDBCASE" /></td>
						  </tr>
						  </form>	
						</table>
						  

							  

						<!-- Table for Bookcase -->
						<form method="post"  action="">	  
						<table class="hovertable">
							<tr>
								<th>Bookcase Name</th><th>Shelf Count</th><th>Shelf Capacity</th><th>   </th>
							</tr>

						<?php
						//Dynamically filling Data into the Table Bookcase
						$result = mysqli_query($conn,  "SELECT * FROM   bookcases  WHERE  user_email = '$username' " );
						if (!$result) {
							echo "Could not successfully run query ($sql) from DB: " . mysql_error();
							exit;
						}
						if (!mysqli_num_rows($result)) {
							echo "No rows found";
						}
						else{
							while ($row = mysqli_fetch_assoc($result)) {
							$a= $row["bookcase"];
							$b= $row["shelf_count"];
							$c= $row["shelf_cap"];
							
							echo " <tr onmouseover=\"this.style.backgroundColor='#ffff66';\" onmouseout=\"this.style.backgroundColor='#d4e3e5';\"> ";
							echo "<td>$a</td>";
							echo "<td>$b</td>";
							echo "<td>$c</td>";
							echo "<td><input name='del' type=\"radio\" value=\" $a \"></td>";
							echo "</tr>";
							}
						}
						?>
						</table>
						<input type="submit" value="Delete BookCase" name="DELBOOKCASE" />
						</form>
</div>


<!-- Form for Adding Books  -->
<div class="title_box" >
<div id="title"><b>Add Books to Your BookCase<b></div>
<div id="content">

									<form method="post"  action="">
									<table width="70%" border="1" cellpadding="1" cellspacing="1" class="test">
									  <tr>
										<td>Select Book Case</td>
									  </tr>
									  
									  <tr>
										<td>
										 <select  name="D1" style="width: 142px"  >
										 <?php
											//Dynamically filling the combo box  with Bookcases
											$result = mysqli_query($conn,  "SELECT * FROM   bookcases  WHERE  user_email = '$username' " );
											if ($result  && mysqli_num_rows($result) ) {
												while ($row = mysqli_fetch_assoc($result)) {
													$b= $row["bookcase"];
													$c= $row["shelf_count"];
													for($i=1;$i<=$c;$i++){
														echo " <option value=\"$b-$i\">$b , Shelf $i </option> ";
													}
												}
										}
										?>
										</select> 
										</td>
										
										<td><input name="D2" value="Title" onfocus="if (this.value == 'Title') this.value=''"/></td>
										<td><input name="D3" value="Author" onfocus="if (this.value == 'Author') this.value=''"/></td>
									  </tr>

									  <tr>
										<td><input name="D4" value="Genre" onfocus="if (this.value == 'Genre') this.value=''"/></td>
										<td><input name="D5" value="ISBN" onfocus="if (this.value == 'ISBN') this.value=''"/></td>
										<td><input name="D6" value="Last Price" onfocus="if (this.value == 'Last Price') this.value=''"/></td>
									  </tr>
									  <tr>
									  <td><input type="submit" value="Add" style="width:142px; margin-top: 10px;margin-bottom: 10px;  " name="ADDBOOK" /></td>
									  </tr>
									  
									</table>
									</form>






									<!-- Table For the Books -->
									<table class="hovertable"    style="width:570px;">
									<tr><th>Bookcase</th><th>Shelf_ID</th><th> Title  </th><th>Author   </th><th> Gener  </th><th>ISBN   </th><th> Price  </th></tr>

									<?php
									//filling data into the table Books
									$result = mysqli_query($conn,  "SELECT * FROM   books   WHERE  user_email = '$username' and bookcase NOT LIKE 'heap'  order by bookcase " );

									if (!$result) {
										echo "Could not successfully run query ($sql) from DB: " . mysql_error();
										exit;
									}
									if (!mysqli_num_rows($result)) {
										echo "No rows found.";

									}
									else{
										while ($row = mysqli_fetch_assoc($result)) {
											
										$a= $row["bookcase"];
										$b= $row["shelf_id"];
										$c= $row["title"];
										$d= $row["author"];
										$e= $row["gener"];
										$f= $row["isbn"];
										$g= $row["price"];
											
										echo " <tr onmouseover=\"this.style.backgroundColor='#ffff66';\" onmouseout=\"this.style.backgroundColor='#d4e3e5';\"> ";
										echo "<td>$a</td>";
										echo "<td>$b</td>";
										echo "<td>$c</td>";
										echo "<td>$d</td>";
										echo "<td>$e</td>";
										echo "<td>$f</td>";
										echo "<td>$g</td>";	
										echo "</tr>";

										}
									}
									?>
									</table>

</div>



	  </section>
 



 <!-- Heap -->
 <section id="friends" class="hidden">


	  
<div class="title_box" >
    <div id="title"><b>Heap<b></div>
    <div id="content">
	
						 <!-- Table for Heap -->
						<table class="hovertable">
						<tr><th> Title  </th><th>Author   </th><th> Gener  </th><th>ISBN   </th><th> Price  </th></tr>

						<?php
						//fill data in table heap dynamically
						$result = mysqli_query($conn,  "SELECT * FROM   books   WHERE  user_email = '$username' AND bookcase='heap' " );

						if (!$result) {
							echo "Could not successfully run query ($sql) from DB: " . mysql_error();
							exit;
						}
						if (!mysqli_num_rows($result)) {
							echo "No rows found";

						}
						else{
							while ($row = mysqli_fetch_assoc($result)) {
							$c= $row["title"];
							$d= $row["author"];
							$e= $row["gener"];
							$f= $row["isbn"];
							$g= $row["price"];
								
							echo " <tr onmouseover=\"this.style.backgroundColor='#ffff66';\" onmouseout=\"this.style.backgroundColor='#d4e3e5';\"> ";
							echo "<td>$c</td>";
							echo "<td>$d</td>";
							echo "<td>$e</td>";
							echo "<td>$f</td>";
							echo "<td>$g</td>";	
							echo "</tr>";

							}
						}
						?>
						</table>
			</div>
      </section>
      

       <!-- About Me -->
      <section id="settings" class="hidden">
        <p>Your Details</p>
        <?php
		
			$q1 = mysqli_query($conn, "SELECT * FROM books  WHERE user_email=\"$username\"  and  bookcase not like \"heap\" "  ) ;
    		$count1=mysqli_num_rows($q1) ;
			
			$q1 = mysqli_query($conn, "SELECT * FROM books  WHERE user_email=\"$username\"  and  bookcase like  \"heap\" "  ) ;
    		$count2=mysqli_num_rows($q1) ;
			
			$q1 = mysqli_query($conn, "SELECT * FROM books  WHERE user_email=\"$username\"  "  ) ;
    		$count3=mysqli_num_rows($q1) ;

		?>
		
		
        <p class="setting"><span>E-mail Address </span><?php echo $username; ?></p>
        
        <p class="setting"><span>Number of Books in BookCase  </span> <?php echo $count1 ?></p>
        
        <p class="setting"><span>Number of Books in Heap  </span> <?php echo $count2 ?></p>
		
        <p class="setting"><span>Total Number of Books  </span> <?php echo $count3 ?></p>		
        
      </section>
    </div><!-- @end #content -->
  </div><!-- @end #w -->
  
  
<script type="text/javascript">
$(function(){
  $('#profiletabs ul li a').on('click', function(e){
    e.preventDefault();
    var newcontent = $(this).attr('href');
    
    $('#profiletabs ul li a').removeClass('sel');
    $(this).addClass('sel');
    
    $('#content section').each(function(){
      if(!$(this).hasClass('hidden')) { $(this).addClass('hidden'); }
    });
    
    $(newcontent).removeClass('hidden');
  });
});
</script>


</body>
</html>

6.   LOGOUT SCRIPT

<?php

if (isset($_COOKIE['loggedin'])) {
    unset($_COOKIE['username']);
    unset($_COOKIE['loggedin']);
	setcookie('loggedin', '', time()-300); 
	setcookie('username', '', time()-300); 	
} 
echo "<script>window.open('index.php','_self')</script>";
?>

7.   MYSQL TABLES

CREATE TABLE IF NOT EXISTS `bookcases` (
  `user_email` varchar(50) NOT NULL,
  `bookcase` varchar(50) NOT NULL,
  `shelf_count` int(5) NOT NULL,
  `shelf_cap` int(5) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `books` (
  `user_email` varchar(20) NOT NULL,
  `bookcase` varchar(20) NOT NULL,
  `shelf_id` int(5) NOT NULL,
  `title` varchar(20) NOT NULL,
  `author` varchar(20) NOT NULL,
  `gener` varchar(20) NOT NULL,
  `isbn` varchar(20) NOT NULL,
  `price` int(5) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


CREATE TABLE IF NOT EXISTS `users` (
  `user_id` int(3) unsigned zerofill NOT NULL AUTO_INCREMENT,
  `user_email` varchar(20) DEFAULT NULL,
  `user_pass` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`user_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s