0% found this document useful (0 votes)
13 views6 pages

PHP MySQL Book Borrowing App Guide

The document describes the steps to create a web application for managing a library with a MySQL database. It includes creating the database, connecting, inserting, deleting, modifying and selecting data, as well as managing students, books, and loans.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

PHP MySQL Book Borrowing App Guide

The document describes the steps to create a web application for managing a library with a MySQL database. It includes creating the database, connecting, inserting, deleting, modifying and selecting data, as well as managing students, books, and loans.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ENSIT ATELIERWEB

TP 6: PHP & MYSQL


OBJECTIFS:

Learning database manipulation in MySQL.


Manipulating a MySQL database through PHP forms.

We propose to create a small application that manages the borrowing of books.


students.
To do this, create a new TP6 site.

I. Creation of the database:


1. Based on the E/A model below, provide the script in a file [Link]
SQL to create the corresponding database.

Student
Book
StudentCode Integer
Name Text Entire Code
0,n Borrow 0,n
First name Text Title Text
Address Text DateEmprunt Date Author Text
Class Text Date Edition Date

2. In phpMyAdmin, create a new database: biblio. Then import and


execute the file containing the SQL code of the database.

II. Connection and disconnection with the database:


[Link] to the database:

▪ In the folder TP6, create the file [Link] containing the code below
below:
<?php
$idcon=mysqli_connect("localhost" ,"root", "");
if($idcon)
{
Connection successful <br/>
$okbd=mysqli_select_db($idcon ,"biblio");
if($okbd==TRUE)
<br/>Correct base <br/>
else
<br/>Base incorrect <br/>
}
else
Connection error with the server:<br/>
?>

▪ Test this code on your browser.


▪ Replace biblioparbiblio1 then test the result… Comments.

Nabil REJEB 1
ENSIT WEB WORKSHOP

[Link] from the database:

In the folder TP6, create the file [Link] containing the code
following:

<?php
$okdec=mysqli_close($idcon);
if($okdec)
Logout successful <br/>
else
Failed to disconnect <br/>
?>

III. Insertion:
[Link]éparer leformulaire d’insertion d’un étudiant: ([Link])

2. In the page new Etud_action.php add the code below and test it:

<?php include("[Link]"); ?>


<?php
$code=$_POST['code'];
$nom=$_POST['nom'];
$prenom=$_POST['prenom'];
$adresse=$_POST['adresse'];
$class=$_POST['class'];
$request="insert into student values
('$code','$nom','$prenom','$adresse','$classe')";
$ok=mysqli_query($idcon, $requet);
if($ok==FALSE)
Insertion problem <br/>
else
Insertion completed successfully <br/>
?>
<?php include("[Link]"); ?>

Nabil REJEB 2
ENSIT ATELIERWEB

IV. Suppression:
1. Prepare the student deletion form: ([Link])

2. In the pagesupprimerEtud_action.php add the code below and the


tester
<?php include ("[Link]"); ?>
<?php
$codeE=$_POST['codeE'];
$request="delete from student where StudentCode = '$codeE'";
$ok= mysqli_query($idcon, $request);
if($ok==FALSE)
Deletion problem <br/>
else
Suppression successful <br/>
?>
<?php include("[Link]"); ?>

V. Modification:
1. Prepare the student modification form: ([Link])

2. In the pagemodifierEtud_action.php prepare the modification action of


data of a student whose request is as follows:

update student set Name='$nom', FirstName='$prenom',


Address ='$address', Class='$class' where StudentCode
='$code';

Nabil REJEB 3
ENSIT ATELIERWEB

VI. Selection:
1. Prepare the [Link] next, allowing to display the list
students:

The code:
<body>
<?php
$idcon=mysqli_connect("localhost", "root", "");
$okbd=mysqli_select_db($idcon, "biblio");
$request="select * from student";
$res= mysqli_query($idcon, $requet);
?>
<table border="2">
<tr>
<th> Code </th>
<th> Name </th>
First Name
Address
Class
</tr>
<?php
while($line=mysqli_fetch_array($res))
{
?>
<tr>
<td><?php echo $row[0]; ?></td>
<td><?php echo $line[1]; ?></td>
<td><?php echo $line[2]; ?></td>
<td><?php echo $line[3]; ?></td>
<td><?php echo $line[4]; ?></td>
</tr>
<?php
}
mysqli_close($idcon);
?>
</table>
</body>

Nabil REJEB 4
ENSIT ATELIERWEB

2. Prepare the search form [Link] to search for a student as follows:

3. In the page rechercheEtud_action.php add the following code:

<?php include("[Link]"); ?>


<?php
$champ=$_POST['champ'];
$valeur=$_POST['valeur'];
$requet="select * from etudiant where $champ = '$valeur'";
$res = mysqli_query($idcon, $request);
$nbr=mysqli_num_rows($res);
if($nbr==0)
<h2>The sought student does not exist in the database</h2><br/>
else
<h2>The requested student exists in the database</h2><br/>
?>
<?php include ("[Link]"); ?>

VII. Student Management Index:


Create the following file [Link] to index the created pages:

Nabil REJEB 5
ENSIT ATELIERWEB

VIII. Book Management:


Repeat the same steps to ensure book management, here is the file
[Link]

IX. Borrowing of books:


Create the [Link], and its various loan management pages:

X. Index:
We end with [Link], the home page of the management application.
library

Nabil REJEB 6

You might also like