Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment: PHP Task for this assignment consists of two parts: Develop a web-ba

ID: 3679395 • Letter: A

Question

Assignment: PHP

Task for this assignment consists of two parts:

Develop a web-based system using HTML, PHP, and MySQL that provides the functionality stated in the Requirements section below.

Make the system that you have created accessible and usable via localhost URL.

Requirements

The five members of a research group, Anne, Bob, Connie, Dean and Eve, want to make some of their books available for loan to other people in their group. The books, their owners, and the number of copies of a particular book owned by a particular researcher are as follows:

That is, in total there are 7 different books, some with more than one copy, some with copies owned by more than one researcher, that the five researchers are willing to loan to others. For example, Bob, Connie and Dean each have copies of `M. Huth and M. Ryan: Logic in Computer Science: Modelling and Reasoning about Systems. Cambridge University Press, 2004', Connie has one copy, Dean has one copy and Bob has two copies of that book.

To keep track to whom a book has been loaned, a web-based library system is to be used. The system should allow a user to

select the book description of a book via a drop-down/pop-up list or selection menu;

select the name of one of the researchers who owns a copy of the book selected via the first list/menu via a separate drop-down/pop-up list or selection menu;

enter the name of the person who borrows the book via a text field;

enter the e-mail address of the person who borrows the book via another text field;

after selecting/entering the data above, submit a borrowing request by pressing a `Submit' button.

Ideally, the user of the system is able to enter all this data via a single web page (not a sequence of two or more pages). However, a sequence of web page can be used if this is the only way that you are able to realise this system.
Also, ideally, the menus are populated with data from the database.

On submission of a borrowing request, the user should be shown a confirmation whether the borrowing request has been successful or unsuccessful. This confirmation should include the book description, the researcher, the name and the e-mail address of the user.

A borrowing request must be successful if the selected researcher is still in the possession of a copy of the selected book, that is, not all copies of the book owned by that researcher have already been loaned by the researcher to someone. If a borrowing request is successful, then that copy of the book is now on loan and the book description, its owner, the name of the person who has borrowed it and the e-mail address of that person must be recorded in the database.

A borrowing request must be unsuccessful if all the copies of the selected book owned by the selected researcher are already on loan. If a borrowing request is unsuccessful then no information is recorded in the database. Also, it should then be possible to select the same or a different book from the same or one of the other researchers. When doing so your system would ideally be programmed in such a way that there is no need to enter name and e-mail address again.

The system would ideally also help the user by only listing in the first menu book descriptions where there are copies left that can be borrowed and, once the user has selected a particular book description in that menu, would in the second menu only list the names of researchers who still having a copy of that book that can be borrowed.

To keep track of the books that are still available and books that have been borrowed, underlying the library system must be a MySQL database storing for each copy of each book whether it is available or has been borrowed and for any borrowed copy of a book the name and e-mail address of the person who has borrowed it.

Additional requirements:

It will be helpful to the user if entries in the two menus are listed in a `sensible' order, that is, book description should be ordered by the surnames of the authors and researchers should also be ordered by their names.

The description of the system above suggests that a user goes through a sequence of five steps in order to submit a borrowing request. However, if you use a single page design for your system, then there is little that prevents a user from skipping a step or skipping all steps before pressing the `Submit' button. Your system should make sure that a request is only processed once the `Submit' button has been pressed and should produce appropriate error messages if the request does not contain all the necessary data.

Note that a user can enter arbitrary strings as name and e-mail address. Names should only consist of the characters a-z, A-Z, hyphen and apostrophe. An e-mail address should only consist of the characters a-z, A-Z, dot, hyphen plus exactly one occurrence of @. You should check that names and e-mail addresses that conform to this format (this check must be performed using PHP not JavaScript) and issue an error message otherwise. Invalid names and invalid e-mail addresses result in an unsuccessful borrowing request.

You should make sure that code injection is not possible.

A user can borrow more than one book and more than one copy of the same book, but a particular copy of a book can only be on loan to one particular user.

There is the possibility that two users nearly simultaneously try to borrow the same book from a particular researcher and that there is only one copy of that book left. Depending on how you implement the interaction with the database, this could lead to a situation in which your system determines for both users that there is still a copy of the book available and then records for both users that he/she has borrowed that copy, with only the information on one of the users remaining in the database but both users receiving a confirmation that their borrowing request has been successful. This is obviously an incorrect behaviour by the library system and needs to be avoided. The borrowing request of exactly one of the two users must be successful and the borrowing request of the other has to be unsuccessful.

As this is an assignment on PHP, the use of other scripting languages should be kept to a minimum, in particular, the use of JavaScript.

The code should be properly commented.

Book description Researcher Number of copies owned by that researcher E. M. Clark, O. Grumberg and D. A. Peled: Model Checking. MIT Press, 1999. Connie 1 M. Fisher: An Introduction to Practical Formal Methods Using Temporal Logic. Wiley, 2011. Eve 1 J. A. Goguen and G. Malcolm: Software Engineering with OBJ. Kluwer, 2000. Anne 1 M. Huth and M. Ryan: Logic in Computer Science: Modelling and Reasoning about Systems. Cambridge University Press, 2004. Bob 2 M. Huth and M. Ryan: Logic in Computer Science: Modelling and Reasoning about Systems. Cambridge University Press, 2004. Connie 1 M. Huth and M. Ryan: Logic in Computer Science: Modelling and Reasoning about Systems. Cambridge University Press, 2004. Dean 1 J.-J. Ch. Meyer and W. van der Hoek: Epistemic Logic for AI and Computer Science. Cambridge University Press, 1995. Connie 2 W. Stallings: Network Security Essentials: Applications and Standards. Prentice Hall, 2000. Anne 1 W. Stallings: Network Security Essentials: Applications and Standards. Prentice Hall, 2000. Bob 1 I. Witten and E. Frank: Data Mining: Practical Machine Learning Tools and Techniques. Morgan Kaufmann, 2005. Dean 1 I. Witten and E. Frank: Data Mining: Practical Machine Learning Tools and Techniques. Morgan Kaufmann, 2005. Eve 1

Explanation / Answer

In Mysql create the database and the tables as follows:

1.create database books

2.use books

3.create a table for inserting the given table using the following commands

create table loans(bookDescription varchar<200>,researcher char<100>,copies int);

4.insert into loans(bookDescription,researcher,copies) values (‘E.M.Clark’,’Connie’,1),(‘M.Fisher’,’Eve’,1),(‘J.A.Goguen’,’Anne’,1),(‘M.Huth’,’Bob’,2),(‘M.huth’,’Connie’,1),(‘J.J.Ch.Meyer’,’Connie’,2),(‘W.Stallings’,’Anne’,1),(‘I.Witten’,’Dean’,1),(‘I.Witten’,’Eve’,1);

5.Create a table to insert person details using the following command

Create table borrows(person char<100>,email varchar<100>,bookDescription varchar<200>);

<html>

<head>

<title>Library System</title>

</head>

<body align=”center”>

<! - - creating a select box for selection of books - - >

<a>Select a book:</a>

<select name=”book”>
  <option value=" E.M.Clark"> E.M.Clark</option>

<option value=" I.Witten"> I.Witten</option>
  <option value=" J.A.Goguen"> J.A.Goguen</option>
  <option value=" J.J.Ch.Meyer"> J.J.Ch.Meyer</option>
  <option value="M.Huth">M.Huth</option>

<option value=" W.Stallings "> W.Stallings</option>
</select></br>

<! - - creating a select box for selection of researcher - - >

<select name=”researcher”>
  <option value=" Anne"> Anne</option>

  <option value=" Bob"> Bob</option>

<option value=" Connie”>Connie</option>
  <option value=" Dean"> Dean</option>
  <option value="Eve">Eve</option>
</select></br>

<! - - creating textboxes for person name and email - - >

Enter your name: <input type=”text” name=”person”></br>

Enter email address:<input type=”email” name=”email”></br>

<! - - creating a submit button- - >

<button type=”submit” value=”submit”>

</body>

</html>

Validate.php:

<html>

<body align=”center”>

<?php

$server='localhost';

$user='root';

$pwd='';

/*connecting to sql server */

$con=mysql_connect($server,$user,$pwd);

/* retrieving user inputs*/

$book=$_POST['book'];

$research=$_POST['researcher'];

$person=$_POST[‘person’];

$email=$_POST['email];

/*selecting mysql database */

mysql_select_db("books",$con);

/*getting number of copies from table in database */

$sql1=mysql_query(“select copies from loans where bookDescription=’$book’ researcher=’$research’”);

$row=mysql_fetch_array($sql);

$number=$row[“copies”];

/*if number of copies greater than 0 enter person details in another table*/

If($number>0)

{

                echo “request successfull”;

                $number = $number – 1;

/*substract number of copies by one and update copies in table */

                mysql_query(“insert into borrows(person,email,bookDescription) values (‘$person’,’$email’,’$book’);

                mysql_query(“update table loans set copies=’$number’ where bookDescription=’$book’ and researcher=’$research’”);

}

else

{

                echo “request failed”;

}

/*close connection */

mysql_close($con);

?>

</body>

</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote