-
Notifications
You must be signed in to change notification settings - Fork 0
/
modify.php
157 lines (125 loc) · 5.97 KB
/
modify.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
session_start();
require './PHP/CRUD/config.php';
if(isset($_POST['nom'])){
$id = $_SESSION['id'];
$sql = "UPDATE clients SET nom=?, prenom=?, telephone=?, adresse=?, complement=?, cp=?, ville=? WHERE id=$id";
if($stmt = mysqli_prepare($conn, $sql)){
mysqli_stmt_bind_param($stmt, "sssssss", $param_nom, $param_prenom, $param_telephone, $param_adresse, $param_complement, $param_cp, $param_ville);
$param_nom = $_POST['nom'];
$param_prenom = $_POST['prenom'];
$param_telephone = $_POST['telephone'];
$param_adresse = $_POST['adresse'];
$param_complement = $_POST['complement'];
$param_cp =$_POST['cp'];
$param_ville = $_POST['ville'];
$message = "modification validée.";
if (mysqli_stmt_execute($stmt)){
header("Location: ./profil.php");
exit();
} else {
echo "erreur";
}
}else{
var_dump($conn);die;
}
mysqli_close($conn);
}else{
if(isset($_GET['id']) && !empty($_GET['id'])){
$id = trim($_GET['id']);
$_SESSION['id'] = $id;
$id = $_SESSION['id'];
$sql = "SELECT * FROM clients WHERE id =?";
if($stmt = mysqli_prepare($conn, $sql)){
if(mysqli_stmt_bind_param($stmt, "i", $param_id)){
$param_id = $id;
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);
if(mysqli_num_rows($result) == 1){
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$_SESSION['nom'] = $row['nom'];
$_SESSION['prenom'] = $row['prenom'];
$_SESSION['telephone'] = $row['telephone'];
$_SESSION['adresse']= $row['adresse'];
$_SESSION['complement'] = $row['complement'];
$_SESSION['cp'] = $row['cp'];
$_SESSION['ville'] = $row['ville'];
} else {
header('Location : ./profil.php');
exit();
}
}
}
}else {
echo "erreur innatendue";
}
}else{
header('location: ./profil.php');
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./CSS/style.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
.wrapper {
width: 600px;
margin: 0 auto;
}
</style>
<title>Mise à jour d'un client</title>
</head>
<body>
<h1>modification du client</h1>
<div class="wrapper">
<div class="container-fluid">
<div class="form-group">
<form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?>" method="post" class="cnx formulaireLogin">
<label for="nom"> Nom
<input class="form-control" type="text" name="nom" id="nom" placeholder="Nom du client" maxlength="255" required
value="<?php echo $_SESSION['nom']; ?>">
</label>
<label for="prenom"> Prenom
<input class="form-control" type="text" name="prenom" id="prenom" placeholder="prenom du client" maxlength="255" required
value="<?php echo $_SESSION['prenom']; ?>">
</label>
<label for="telephone"> Telephone
<input class="form-control" type="text" name="telephone" id="telephone" placeholder="telephone du client" maxlength="20" required
value="<?php echo $_SESSION['telephone']; ?>">
</label>
<label for="adresse"> adresse
<input class="form-control" type="text" name="adresse" id="adresse" placeholder="adresse du client" maxlength="255" required
value="<?php echo $_SESSION['adresse']; ?>">
</label>
<label for="complement"> complement
<input class="form-control" type="text" name="complement" id="complement" placeholder="complement du client" maxlength="255"
value="<?php echo $_SESSION['complement']; ?>">
</label>
<label for="cp"> cp
<input class="form-control" type="text" name="cp" id="cp" placeholder="cp du client" maxlength="50" required
value="<?php echo $_SESSION['cp']; ?>">
</label>
<label for="ville"> ville
<input class="form-control" type="text" name="ville" id="ville" placeholder="ville du client" maxlength="255" required
value="<?php echo $_SESSION['ville']; ?>">
</label>
<input class="btnSubmit btn btn-primary" type="submit" value="Valider">
<button class="btnSubmit btn btn-secondary" value="Annuler"><a href='./profil.php'>Annuler</a></button>
</form>
</div>
</div>
</div>
<?php
if (!empty($erreur) && $erreur != "") {
echo '<div class="erreur"> <p>' . $erreur . '</p> </div>';
}
?>
</body>
</html>