This commit is contained in:
OMGiTzPomPom 2022-09-20 09:46:06 +02:00
parent 3ef5375b73
commit 56a0519cee
6 changed files with 136 additions and 0 deletions

BIN
TP/TP2.docx Normal file

Binary file not shown.

23
TP/TP2_codes/connect.php Normal file
View File

@ -0,0 +1,23 @@
<?php
// ------------------------------------------------------------------- //
// Test de connexion à MySQL
// ------------------------------------------------------------------ //
$sql_host = "localhost";
$sql_user = $_GET['login'];
$sql_pwd = $_GET['motdepasse'];
//$sql_port = "3306";//pas du tout obligatoire si vous avez laissé le //port par défaut
$sql_db = $_GET['dbname'];
// Create connection
$conn = new mysqli($sql_host, $sql_user, $sql_pwd, $sql_db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "<br/>"."Connexion reussie :)..."."<br/>";
// Close connexion
$conn->close();
?>

22
TP/TP2_codes/index.php Normal file
View File

@ -0,0 +1,22 @@
<html><body>
<h1>MyCorp server connexion a BD</h1>
<p>Page de cotainnexion à ma base de données</p>
<form method="get" action="connect.php">
<fieldset>
<legend>Login : </legend>
<input type="text" name="login"/>
</fieldset>
<fieldset>
<legend>Password : </legend>
<input type="password" name="motdepasse"/>
</fieldset>
<fieldset>
<legend>DataBase Name : </legend>
<input type="text" name="dbname"/>
</fieldset>
<input type="submit" name="submit" value="Se connecter"/>
</form>
</body></html>

View File

@ -0,0 +1,17 @@
<html><body>
<h1>Récupération MDP</h1>
<p>Page de connexion à ma base de données</p>
<form method="get" action="tp2.php">
<fieldset>
<legend>Login : </legend>
<input type="text" name="login"/>
</fieldset>
<fieldset>
<legend>Mot de passe : </legend>
<input type="password" name="motdepasse"/>
</fieldset>
<input type="submit" name="submit" value="Se connecter"/>
</form>
</body></html>

View File

@ -0,0 +1,64 @@
<?php
// ------------------------------------------------------------------------- //
// Test de connection à MySQL //
// ------------------------------------------------------------------------- //
echo "Bonjour \n";
//Éditez les varibales ci dessous
/*if(!isset($_GET['login']) && !isset($_GET['motdepasse']))
{
header('Location: index.php');
print ("login et pass ok <br/>");
}else{
// On va vérifier les variables
print("Verification du login et pass<br/>");
if(!preg_match('/^[[:alnum:]]+$/', $_GET['login']) or
!preg_match('/^[[:alnum:]]+$/', $_GET['motdepasse']))
{
echo 'Vous devez entrer uniquement des lettres ou des chiffres <br/>';
echo '<a href="index.php" temp_href="index.php">Ressayer</a>';
exit();
}
}
*/
$sql_host = "localhost";
$sql_user = "iut";
$sql_pwd = "iut";
$sql_db = "BD_TP2";
// Create connection
$conn = new mysqli($sql_host, $sql_user, $sql_pwd, $sql_db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "<br/>"."Connexion reussie :)..."."<br/>";
$nom = $_GET['login'];
$motdepasse = $_GET['motdepasse'];
print ("nom = $nom, mdp = $motdepasse");
echo "<br/>New record created successfully";
/*
//select des cartes
// on envoie la requête
$sql ="SELECT numerocarte FROM comptes WHERE (nom = '$nom' AND motdepasse = '$m$
$req = $conn->query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
$row = $req->fetch_assoc();
echo "<br>";
echo "numero de carte = ";
echo $row['numerocarte'];
//Fermeture de la connexion
$conn->close();
*/
?>

10
TP/TP2_codes/test.php Normal file
View File

@ -0,0 +1,10 @@
<html>
<body><h1>Test PHP </h1>
<p>This is the PHP web page for this server.</p>
<?php
$date = date("d-m-Y");
$heure = date("H:i");
Print("Bonjour Nous sommes le $date et il est $heure");
?>
</body>
</html>