Sunteți pe pagina 1din 21

MINISTERUL EDUCAŢIEI, CULTURII ȘI CERCETĂRII AL

REPUBLICII MOLDOVA
CENTRUL DE EXCELENŢĂ ÎN INFORMATICĂ

ŞI TEHNOLOGII INFORMAŢIONALE

Lucrare individuală nr. 2


Tema:”Baze de date în aplicații web”

Disciplina: Tehnologii moderne de programare

Elevul :

Beșelea Dumitru, I-1546

Profesor:

Gonța V.

Chişinău

2018
Cuprins
I. Conținutul site-ului ............................................................................................................................. 3
 Structura logică ................................................................................................................................. 3
 Structura fizică .................................................................................................................................. 3
II. Codul aplicației web. ............................................................................................................................. 5
a) emai.php ........................................................................................................................................... 5
b) registr.php ........................................................................................................................................ 6
c) A.php ................................................................................................................................................ 8
d) A1.php .............................................................................................................................................. 8
e) b.php ................................................................................................................................................. 9
f) b1.php .............................................................................................................................................11
g) d.php ...............................................................................................................................................12
h) d1.php .............................................................................................................................................12
i) d3.php .............................................................................................................................................16
j) e.php ...............................................................................................................................................16
k) radio.css ..........................................................................................................................................17
l) s.css .................................................................................................................................................18
III. Concluzie.........................................................................................................................................21
IV. Bibliografie .....................................................................................................................................21
I. Conținutul site-ului
 Structura logică

 Structura fizică

emai.php
registr.php

b.php

e.php
D.php

D1.php

D3.php

II. Codul aplicației web.


a) emai.php
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="1.png"/>
<title>Votarea</title>
</head>
<body style="background-color: #76b852; height: 50;
width: 360px;
padding: 8% 0 0;
margin: auto;">
<form method="POST" action="a.php" style="
position: relative;
z-index: 1;
background: #FFFFFF;
max-width: 360px;
margin: 0 auto 100px;
padding: 45px;
text-align: center;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0
rgba(0, 0, 0, 0.24);">
<br>
<h2>Logarea</h2>
<br>
<input style="border-color:#f2f2f2; padding: 16px 50px;text-decoration:
none;margin: 1px 0px; cursor: pointer;" align="center" type="text"
name="Username" placeholder="Username"><br><br>
<input style="
border-color:#f2f2f2;
padding: 16px 50px;
text-decoration: none;
margin: 1px 0px;
cursor: pointer;" type="password" name="Password" placeholder="Password"
><br><br>

<input style="
background: #4CAF50;
width: 100%;
border: 0;
padding: 15px;
color: #FFFFFF;
font-size: 14px;
-webkit-transition: all 0.3 ease;
transition: all 0.3 ease;
cursor: pointer;" align="center" type="submit" name="OK" value="OK">

<p style="
margin: 15px 0 0;
color: #b3b3b3;
font-size: 14px;">Nu ești înregistrat? <a style="color: #4CAF50;
text-decoration: none;" href="registr.php">Crează un account</a></p>
</body>
</html>
b) registr.php
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="1.png"/>
<title>Votarea</title>
</head>
<body style="background-color: #76b852; height: 50;
width: 360px;
padding: 8% 0 0;
margin: auto;">
<form method="POST" action="a1.php" style="
position: relative;
z-index: 1;
background: #FFFFFF;
max-width: 360px;
margin: 0 auto 100px;
padding: 45px;
text-align: center;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0
rgba(0, 0, 0, 0.24);">
<br>
<h2>Înregistreazăte</h2>
<br>
<input style="border-color:#f2f2f2; padding: 16px 50px;text-decoration:
none;margin: 1px 0px; cursor: pointer;" align="center" type="text"
name="Username" placeholder="Username"><br><br>

<input style="
border-color:#f2f2f2;
padding: 16px 50px;
text-decoration: none;
margin: 1px 0px;
cursor: pointer;" type="text" name="IDNP" placeholder="IDNP" ><br><br>

<input style="border-color:#f2f2f2; padding: 16px 50px;text-decoration:


none;margin: 1px 0px; cursor: pointer;" align="center" type="password"
name="Password" placeholder="Password"><br><br>

<input style="
border-color:#f2f2f2;
padding: 16px 50px;
text-decoration: none;
margin: 1px 0px;
cursor: pointer;" type="password" name="Password1" placeholder="Password
confirmare" ><br><br>

<input style="
background: #4CAF50;
width: 100%;
border: 0;
padding: 15px;
color: #FFFFFF;
font-size: 14px;
-webkit-transition: all 0.3 ease;
transition: all 0.3 ease;
cursor: pointer;" align="center" type="submit" name="OK"
value="Înregistrează">
<p style="
margin: 15px 0 0;
color: #b3b3b3;
font-size: 14px;">Ești înregistrat? <a style="color: #4CAF50;
text-decoration: none;" href="emai.php">Logheazăte</a></p>
</body>
</html>
c) A.php
<?php
$servername = "localhost";
$root = "root";
$password = "";
$db="vot";
$conn =mysqli_connect($servername, $root, $password,$db);
$Username=$_POST['Username'];
$Password=$_POST['Password'];
$salted="4234ggdfgdgdGG".$Password."345678778vvgvjgvg";
$hashed=hash('sha512',$salted);
$sql =mysqli_query($conn,"select *from `cetateni` where
`Username`='$Username' && `Password`='$hashed'");
$count=mysqli_num_rows($sql);
if ($count==1){
header("location:b.php");
}
else
{
header("location:emai.php");
}
?>
d) A1.php
<?php
$servername = "localhost";
$root = "root";
$password = "";
$db="vot";
$conn =mysqli_connect($servername, $root, $password,$db);
$Username=$_POST['Username'];
$Prenumele=$_POST['Prenumele'];
$IDNP=$_POST['IDNP'];
$Password=$_POST['Password'];
$Password1=$_POST['Password1'];
if ($Password==$Password1)
{
//criptarea parolei
$salted="4234ggdfgdgdGG".$Password."345678778vvgvjgvg";
$hashed=hash('sha512',$salted);
//criptarea idnp
$salted1="4234ggdfgdgdGG".$IDNP."345678778vvgvjgvg";
$hashed1=hash('sha512',$salted1);
$sql =mysqli_query($conn,"INSERT INTO cetateni(Username,IDNP,Password)
VALUES ('$Username', '$hashed1','$hashed')");
header("location:emai.php");
}
else
header("location:registr.php");
?>
e) b.php
<style>
.navigation {
width: 100%;
background-color: black;
}
img {
width: 25px;
border-radius: 50px;
float: left;
}
.logout {
font-size: .8em;
font-family: 'Oswald', sans-serif;
position: relative;
right: -18px;
bottom: -4px;
overflow: hidden;
letter-spacing: 3px;
opacity: 0;
transition: opacity .45s;
-webkit-transition: opacity .35s;

.button {
text-decoration: none;
float: right;
padding: 12px;
margin: 15px;
color: white;
width: 25px;
background-color: black;
transition: width .35s;
-webkit-transition: width .35s;
overflow: hidden
}
a:hover {
width: 100px;
}

a:hover .logout{
opacity: .9;
}
a{
text-decoration: none;
}
</style>
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="1.png"/>
<title>Votarea</title>
</head>
<body>

<div class="navigation">
<a class="button" href="e.php">
<img src="images.png">
<div class="logout" >Ieși</div>
</a>
</div>
<br>
<h2 style="text-align: center">Votează</h2>
<br><br><br>
<br><br>

<link href="radio.css" rel="stylesheet">


<form method="POST" action="b1.php">

<ul>
<li>
<input style="background: transparent; height: 50px; width: 100%; text-
decoration-color: red;" align="center" type="text" name="IDNP"
placeholder="IDNP">
</li>
<li>
<input type="radio" id="f-option" name="partid" value="Partidul democrat din
Republica Moldova">
<label for="f-option">Partidul democrat din Republica Moldova</label>
<div class="check"></div>
</li>

<li>
<input type="radio" id="s-option" name="partid" value="Partidul Liberal">
<label for="s-option">Partidul Liberal</label>

<div class="check"><div class="inside"></div></div>


</li>

<li>
<input type="radio" id="t-option" name="partid" value="Paridul Socialistilor
din Republica Moldova">
<label for="t-option">Paridul Socialistilor din Republica Moldova</label>
<div class="check"><div class="inside"></div></div>
</li>

<li>
<input type="radio" id="r-option" name="partid" value="Paridul Liberal
Democrat din Moldova">
<label for="r-option">Paridul Liberal Democrat din Moldova</label>
<div class="check"><div class="inside"></div></div>
</li>

</ul>
</div>
<br><br><br><br>
<input style="
background: #4CAF50;
width: 50%;
border: 0;
padding: 15px;
margin-left:auto;
margin-right:auto;
display:block;
margin-top:22%;
margin-bottom:0%
color: #FFFFFF;
font-size: 20px;
-webkit-transition: all 0.3 ease;
transition: all 0.3 ease;
cursor: pointer;" align="center" type="submit" name="OK" value="Votează">
</form>
</body>
</html>
f) b1.php
<?php
$root = "root";
$password = "";
$hostname ="localhost";
$dbhandle=mysqli_connect($hostname, $root, $password,"vot") or die ("Dima");
if (isset($_POST['IDNP']) && isset($_POST['partid'])){
$IDNP=$_POST['IDNP'];
$partid=$_POST['partid'];
$salted1="4234ggdfgdgdGG".$IDNP."345678778vvgvjgvg";
$hashed1=hash('sha512',$salted1);
$query=mysqli_query($dbhandle,"SELECT * FROM partiduri WHERE
IDNP='$hashed1'");
if (mysqli_num_rows($query)>0) {
header("location:d3.php");
}
else
{
$sql =mysqli_query($dbhandle,"INSERT INTO
partiduri(IDNP,partid) VALUES ('$hashed1','$partid')");
header("location:d.php");
}
}
?>
g) d.php
<!DOCTYPE html>
<html>
<head>
<title>Votarea</title>
<link rel="icon" href="1.png"/>
</head>
<body style="background-color: #76b852; height: 50;
width: 360px;
padding: 8% 0 0;
margin: auto;">
<form method="POST" action="d1.php" style="
position: relative;
z-index: 1;
background: #FFFFFF;
max-width: 360px;
margin: 0 auto 100px;
padding: 45px;
text-align: center;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0
rgba(0, 0, 0, 0.24);">
<br>
<h2>Ați votat cu succes!!!</h2>
<br>
<input style="
background: #4CAF50;
width: 100%;
border: 0;
padding: 15px;
color: #FFFFFF;
font-size: 14px;
-webkit-transition: all 0.3 ease;
transition: all 0.3 ease;
cursor: pointer;" align="center" type="submit" name="OK" value="Numărul de
voturi al partidelor">
</body>
</html>
h) d1.php
<!DOCTYPE html>
<html>
<head>
<title>Votarea</title>
<link rel="icon" href="1.png"/>
</head>
<body style="background-color: #76b852; height: 50;
width: 400px;
padding: 8% 0 0;
margin: auto;">
<form method="POST" action="a.php" style="
background: #FFFFFF;
max-width: 360px;
padding: 50px;
box-shadow: 0 0 0px 0 rgba(0, 0, 0, 0.2), 0 0px 0px 0
rgba(0, 0, 0, 0.24);">
<br>
<h2 style="text-align: center;">Rezulatele voturilor:</h2>
<?php
echo "Partidul democrat din Republica Moldova: ";

class TableRows extends RecursiveIteratorIterator {


function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}

function current() {
return "<td style='width: 150px; border: 1px solid black;'>" .
parent::current(). "</td>";
}

function beginChildren() {
echo "<tr>";
}

function endChildren() {
echo "</tr>" . "\n";
}
}

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "vot";

try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username,
$password);
$conn->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT COUNT(partid) FROM partiduri WHERE
partid='Partidul democrat din Republica Moldova'");
$stmt->execute();

$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);

foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as


$k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
?>

<?php
echo "<br><br>";
echo "Partidul Liberal: ";
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "vot";

try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username,
$password);
$conn->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT COUNT(partid) FROM partiduri WHERE
partid='Partidul Liberal'");
$stmt->execute();

$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);

foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as


$k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
?>
<?php
echo "<br><br>";
echo "Paridul Socialistilor din Republica Moldova: ";
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "vot";

try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username,
$password);
$conn->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT COUNT(partid) FROM partiduri WHERE
partid='Paridul Socialistilor din Republica Moldova'");
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);

foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as


$k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
?>
<?php
echo "<br><br>";
echo "Paridul Liberal Democrat din Moldova: ";
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "vot";

try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username,
$password);
$conn->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT COUNT(partid) FROM partiduri WHERE
partid='Paridul Liberal Democrat din Moldova'");
$stmt->execute();

$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);

foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as


$k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
/*echo "</table>";*/
?>
<br><br><br>
<input style="
background: #4CAF50;
width: 100%;
border: 0;
padding: 15px;
color: #FFFFFF;
font-size: 18px;
-webkit-transition: all 0.3 ease;
transition: all 0.3 ease;
cursor: pointer;" align="center" type="submit" name="OK" value="Iesire">
</form>
</body>
</html>
i) d3.php
<!DOCTYPE html>
<html>
<head>
<title>Votarea</title>
<link rel="icon" href="1.png"/>
</head>
<body style="background-color: #76b852; height: 50;
width: 360px;
padding: 8% 0 0;
margin: auto;">
<form method="POST" action="d1.php" style="
position: relative;
z-index: 1;
background: #FFFFFF;
max-width: 360px;
margin: 0 auto 100px;
padding: 45px;
text-align: center;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0
rgba(0, 0, 0, 0.24);">
<br>
<h2>Ați votat deja!!!</h2>
<br>
<input style="
background: #4CAF50;
width: 100%;
border: 0;
padding: 15px;
color: #FFFFFF;
font-size: 14px;
-webkit-transition: all 0.3 ease;
transition: all 0.3 ease;
cursor: pointer;" align="center" type="submit" name="OK" value="Numărul de
voturi al partidelor">
</body>
</html>
j) e.php
<form class="form" method="POST" action="emai.php">
<h2>Doriți să vă deconectați? </h2>
<div class="inputGroup" onclick="return confirm('Sunteți sigur că doriți să vă
deconectați?');">
<input id="radio1" name="radio" type="radio" value="Yes"
onClick="window.location = 'http://localhost/votare/emai.php';"/>
<label for="radio1">Yes</label>
</div>
<div class="inputGroup">
<input id="radio2" name="radio" type="radio" onClick="window.location =
'http://localhost/votare/b.php';"/>
<label for="radio2">No</label>
</div>
</form>
<link href="s.css" rel="stylesheet">
k) radio.css
body, html{
height: 90%;
background: #222222;
font-family: 'Lato', sans-serif;
}
.container{
display: block;
position: relative;
margin: 20px auto;
height: auto;
width: 500px;
padding: 20px;
}

h2 {
color: #AAAAAA;
}

.container ul{
list-style: none;
margin: 0;
padding: 0;
overflow: auto;
}

ul li{
color: #AAAAAA;
display: block;
position: relative;
float: left;
width: 100%;
height: 70px;
border-bottom: 0.5px solid #333;
}

ul li input[type=radio]{
position: absolute;
visibility: hidden;
}

ul li label{
display: block;
position: relative;
font-weight: 200;
font-size: 1.25em;
padding: 25px 25px 25px 80px;
margin: 10px auto;
height: 30px;
z-index: 9;
cursor: pointer;
-webkit-transition: all 0.25s linear;
}

ul li:hover label{
color: #FFFFFF;
}

ul li .check{
display: block;
position: absolute;
border: 5px solid #AAAAAA;
border-radius: 100%;
height: 25px;
width: 25px;
top: 30px;
left: 20px;
z-index: 5;
transition: border .25s linear;
-webkit-transition: border .25s linear;
}

ul li:hover .check {
border: 5px solid #FFFFFF;
}

ul li .check::before {
display: block;
position: absolute;
content: '';
border-radius: 100%;
height: 15px;
width: 15px;
top: 5px;
left: 5px;
margin: auto;
transition: background 0.25s linear;
-webkit-transition: background 0.25s linear;
}

input[type=radio]:checked ~ .check {
border: 5px solid #0DFF92;
}

input[type=radio]:checked ~ .check::before{
background: #0DFF92;
}

input[type=radio]:checked ~ label{
color: #0DFF92;
}
l) s.css
.inputGroup {
background-color: #fff;
display: block;
margin: 10px 0;
position: relative;
}
.inputGroup label {
padding: 12px 30px;
width: 100%;
display: block;
text-align: left;
color: #3C454C;
cursor: pointer;
position: relative;
z-index: 2;
transition: color 200ms ease-in;
overflow: hidden;
}
.inputGroup label:before {
width: 10px;
height: 10px;
border-radius: 50%;
content: '';
background-color: #5562eb;
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%) scale3d(1, 1, 1);
transform: translate(-50%, -50%) scale3d(1, 1, 1);
transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1);
opacity: 0;
z-index: -1;
}
.inputGroup label:after {
width: 32px;
height: 32px;
content: '';
border: 2px solid #D1D7DC;
background-color: #fff;
background-image: url("data:image/svg+xml,%3Csvg width='32' height='32'
viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath
d='M5.414 11L4 12.414l5.414 5.414L20.828 6.414 19.414 5l-10 10z'
fill='%23fff' fill-rule='nonzero'/%3E%3C/svg%3E ");
background-repeat: no-repeat;
background-position: 2px 3px;
border-radius: 50%;
z-index: 2;
position: absolute;
right: 30px;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
cursor: pointer;
transition: all 200ms ease-in;
}
.inputGroup input:checked ~ label {
color: #fff;
}
.inputGroup input:checked ~ label:before {
-webkit-transform: translate(-50%, -50%) scale3d(56, 56, 1);
transform: translate(-50%, -50%) scale3d(56, 56, 1);
opacity: 1;
}
.inputGroup input:checked ~ label:after {
background-color: #54E0C7;
border-color: #54E0C7;
}
.inputGroup input {
width: 32px;
height: 32px;
order: 1;
z-index: 2;
position: absolute;
right: 30px;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
cursor: pointer;
visibility: hidden;
}

.form {
padding: 0 16px;
max-width: 550px;
margin: 80px auto;
margin-top: 180px;
font-size: 18px;
font-weight: 600;
line-height: 36px;
}

body {
background-color: #D1D7DC;
font-family: 'Fira Sans', sans-serif;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
html {
box-sizing: border-box;
}
code {
background-color: #9AA3AC; padding: 0 8px;}
III. Concluzie
Efectuînd această lucrare individuală pot să deduc foarte multe lucruri și concluzii, dar
cel mai important consider că după finisarea ei apar deja unele deprinderi din domeniu, și aceasta
mi-a dat posibilitatea de a înțelege cu adevarăt importanța profesiei alese.
Cu ajutorul acestei lucrări individuale am putut înţelege mai bine cum să creez un site și
cum să fac conectarea unui site cu baze de date cu ajutorului limbajului PHP. La fel am înţeles că
trebuie să te atîrni destul de serios faţă de aceea ce faci. Mi-au apărut unele idei pe viitor la care
mă gândeam înainte dar nu ştiam cum să le fac.
Studentul începător se familiarizează cu crearea aplicațiilor web, de regulă, în baza crearea
aplicațiilor web concrete simple. La rîndul său, lucrarea individuală imită întregul process de
elaborare a unei aplicații web.
Consider că pentru un programator bun în primul rînd este necesară lucrarea individuală,
deoarece doar prin lucrare putem analiza și aplica cunoștințele teoretice pe care le-am acumulat și
care de foarte multe ori nu sunt înțelese pînă la urmă .

IV. Bibliografie
http://php.net/manual/en/security.database.sql-injection.php
https://www.w3schools.com/html/html_forms.asp
https://www.w3schools.com/php/php_mysql_insert.asp

S-ar putea să vă placă și