tp8
This commit is contained in:
parent
1394656120
commit
84d743bad5
16
2020-2021/TD8/ajout.html
Normal file
16
2020-2021/TD8/ajout.html
Normal file
@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Ajout d'une entrée</title>
|
||||
</head>
|
||||
<body>
|
||||
<form method="post" action="ajoutEntree.php">
|
||||
<label>Nom</label><input id="nom" type="text" name="nom" required><br/>
|
||||
<label>Prenom</label><input id="prenom" type="text" name="prenom" required><br/>
|
||||
<label>NumPost</label><input id="numpost" type="text" name="numpost" required><br/>
|
||||
<input type="submit" name="submit">
|
||||
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
12
2020-2021/TD8/ajoutEntree.php
Normal file
12
2020-2021/TD8/ajoutEntree.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
$connect = new mysqli($servername, $username, $password, $dbname);
|
||||
if($connect->connect_errno){
|
||||
die("Connexion impossible");
|
||||
}else{
|
||||
echo "Connexion OK";
|
||||
}
|
||||
|
||||
$insert = "INSERT INTO ANNUAIRE (nom,prenom,numPost) VALUES (?,?,?)";
|
||||
$stmt = $connect->prepare($insert);
|
||||
$stmt->bind_param("sss",$_POST["nom"],$_POST["prenom"],$_POST["numpost"]);
|
||||
$stmt->execute();
|
15
2020-2021/TD8/createTable.php
Normal file
15
2020-2021/TD8/createTable.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
$connect = new mysqli($servername, $username, $password, $dbname);
|
||||
if ($connect->connect_errno) {
|
||||
die("Connexion impossible");
|
||||
} else {
|
||||
echo "Connexion OK";
|
||||
}
|
||||
$nom = "Bar";
|
||||
$rechercheNom = "SELECT * from ANNUAIRE WHERE nom like'" . $nom . "%'";
|
||||
$SearchPrenome = "SELECT * from ANNUAIRE WHERE nom like'" . $prenom . "%'";
|
||||
$result = $connect->query($rechercheNom);
|
||||
while ($r = $result->fetch_assoc()) {
|
||||
echo '<br/>' . $r["nom"] . " " . $r["prenom"] . " " . $r["numPost"] . " " . $r["id"];
|
||||
}
|
||||
$connect->close();
|
23
2020-2021/TD8/database.php
Normal file
23
2020-2021/TD8/database.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* ----------------------------------------------------------------------------
|
||||
* | database.php |
|
||||
* | Objectif : paramétrer la base de données |
|
||||
* | |
|
||||
* | @author JunkJumper |
|
||||
* | @copyright 2019 - JunkJumper |
|
||||
* | @license https://creativecommons.org/licenses/by/4.0/ License CC BY 4.0|
|
||||
* | @since File available since 10/08/2019 |
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* Le but de ce script est de définir les variables pour vos connexions à vos BDD
|
||||
*/
|
||||
|
||||
$servername = "linserv-info-01.iutnice.unice.fr"; //Vous devez remplacer ici le "localhost" par l'adresse de votrebase de données
|
||||
$username = "sj801446"; //Vous devez indiquer votre nom d'utilisateur pour accèder à la base de données
|
||||
$password = "sj801446"; //Vous devez indiquer ici le mot de passe
|
||||
$dbname = "sj801446_"; //Vous devez remplace le "database" par le nom de votre base de données.
|
||||
|
||||
|
||||
|
||||
?>
|
14
2020-2021/TD8/index.html
Normal file
14
2020-2021/TD8/index.html
Normal file
@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Menu</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Que voulez vous faire</h1>
|
||||
<a href="recherche.html">Recehercher une entrée</a>
|
||||
<a href="ajout.html">Ajouter une entrée</a>
|
||||
<a href="modifnumpost.html">Modifier numero de poste</a>
|
||||
<a href="supprimer.html">Supprimer une entrée</a>
|
||||
</body>
|
||||
</html>
|
15
2020-2021/TD8/modifier.php
Normal file
15
2020-2021/TD8/modifier.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
$connect = new mysqli($servername, $username, $password, $dbname);
|
||||
if($connect->connect_errno){
|
||||
die("Connexion impossible");
|
||||
}else{
|
||||
echo "Connexion OK".'<br/>';
|
||||
}
|
||||
|
||||
$sql ="UPDATE ANNUAIRE SET numPost='".$_POST["numpost"]."' WHERE nom='".$_POST["nom"]."' and prenom='".$_POST["prenom"]."'";
|
||||
if($connect->query($sql)===TRUE && $connect->affected_rows>0){
|
||||
echo "Mise à jour OK".'<br/>';
|
||||
}
|
||||
else{
|
||||
echo "Erreur lors de la mise à jour : ".$connect->error;
|
||||
}
|
16
2020-2021/TD8/modifnumpost.html
Normal file
16
2020-2021/TD8/modifnumpost.html
Normal file
@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Modifier un numero de poste</title>
|
||||
</head>
|
||||
<body>
|
||||
<form method="post" action="modifier.php">
|
||||
<label>Nom </label><input id="nom" type="text" name="nom" ><br/>
|
||||
<label>Prenom</label><input id="prenom" type="text" name="prenom" ><br/>
|
||||
<label>Nouveau numéro de poste</label><input id="numpost" type="text" name="numpost" ><br/>
|
||||
<input type="submit" name="submit">
|
||||
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
15
2020-2021/TD8/recherche.html
Normal file
15
2020-2021/TD8/recherche.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>recherche dans table ANNUAIRE</title>
|
||||
</head>
|
||||
<body>
|
||||
<form method="post" action="rechercheTable.php">
|
||||
<label>Par nom</label><input id="nom" type="text" name="nom" ><br/>
|
||||
<label>Par prenom</label><input id="prenom" type="text" name="prenom" ><br/>
|
||||
<input type="submit" name="submit">
|
||||
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
29
2020-2021/TD8/rechercheTable.php
Normal file
29
2020-2021/TD8/rechercheTable.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
$connect = new mysqli($servername, $username, $password, $dbname);
|
||||
if($connect->connect_errno){
|
||||
die("Connexion impossible");
|
||||
}else{
|
||||
echo "Connexion OK";
|
||||
}
|
||||
$nom="Bar";
|
||||
$rechercheNom = "SELECT * from ANNUAIRE WHERE nom like'". $_POST["nom"]."%'";
|
||||
$recherchePrenom = "SELECT * from ANNUAIRE WHERE nom like'".$_POST["prenom"]."%'";
|
||||
$rechercheNomEtPrenom= "SELECT * from ANNUAIRE WHERE prenom like'".$_POST["prenom"]."%' and nom like'". $_POST["nom"]."%'";
|
||||
if(!empty($_POST["prenom"]) && !empty($_POST["nom"])){
|
||||
$result = $connect->query($rechercheNomEtPrenom);
|
||||
}
|
||||
elseif (!empty ($_POST["prenom"])) $result = $connect->query($recherchePrenom);
|
||||
elseif ( !empty ($_POST["nom"])) $result = $connect->query($rechercheNom);
|
||||
echo '<br/>'."Resultat de la recherche";
|
||||
while($r=$result->fetch_assoc()) {
|
||||
echo '<br/>'.$r["nom"]." ".$r["prenom"]." ".$r["numPost"]." ".$r["id"];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$connect->close();
|
||||
|
15
2020-2021/TD8/supprimer.html
Normal file
15
2020-2021/TD8/supprimer.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Supprimer une entrée</title>
|
||||
</head>
|
||||
<body>
|
||||
<form method="post" action="supprimer.php">
|
||||
<label>Nom</label><input id="nom" type="text" name="nom" ><br/>
|
||||
<label>Prenom</label><input id="prenom" type="text" name="prenom" ><br/>
|
||||
<input type="submit" name="submit">
|
||||
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
14
2020-2021/TD8/supprimer.php
Normal file
14
2020-2021/TD8/supprimer.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
$connect = new mysqli($servername, $username, $password, $dbname);
|
||||
if ($connect->connect_errno) {
|
||||
die("Connexion impossible");
|
||||
} else {
|
||||
echo "Connexion OK" . '<br/>';
|
||||
}
|
||||
|
||||
$sql = "DELETE FROM ANNUAIRE WHERE nom='" . $_POST["nom"] . "' and prenom='" . $_POST["prenom"] . "'";
|
||||
if ($connect->query($sql) === TRUE && $connect->affected_rows > 0) {
|
||||
echo "Suppression OK" . '<br/>';
|
||||
} else {
|
||||
echo "Erreur lors suppression : " . $connect->error;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user