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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
|
<?php
// Include config file
require_once 'config.php';
// Define variables and initialize with empty values
$Numero = $PR = $Releve = $Commentaires = "";
$Numero_err = $PR_err = $Releve_err = $Commentaires_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Validate PR
$input_PR = trim($_POST["PR"]);
if(empty($input_PR)){
$PR_err = "Saisissez votre PR+Abs.";
// } elseif(!filter_var(trim($_POST["PR"]), FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z'-.\s ]+$/")))){
// $PR_err = 'Please enter a valid PR.';
} else{
$PR = $input_PR;
}
// Validate Relever
$input_Releve = trim($_POST["Releve"]);
if(empty($input_Releve)){
$Releve_err = 'Veuillez entrer votre relevé.';
} else{
$Releve = $input_Releve;
}
// Validate Commentaires
$input_Commentaires = trim($_POST["Commentaires"]);
if(empty($input_Commentaires)){
$Commentaires_err = "Veuillez entrer votre commentaire.";
//} elseif(!ctype_digit($input_Commentaires)){
// $Commentaires_err = 'Please enter a positive integer value.';
} else{
$Commentaires = $input_Commentaires;
}
// Check input errors before inserting in database
if (empty($Numero_err) && empty($PR_err) && empty($Releve_err) && empty($Commentaires_err)){
// Prepare an insert statement
$sql = "INSERT INTO isri (Numero, PR, Releve, Commentaires) VALUES (?, ?, ?, ?)";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "isss", $Numero, $param_PR, $param_Releve, $param_Commentaires);
// Set parameters
$param_PR = $PR;
$param_Releve = $Releve;
$param_Commentaires = $Commentaires;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Records created successfully. Redirect to landing page
header("location: index.php");
exit();
} else{
echo "Something went wrong. Please try again later.";
}
}
// Close statement
mysqli_stmt_close($stmt);
}
// Close connection
mysqli_close($link);
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Create Record</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<style type="text/css">
.wrapper{
width: 500px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h2>Créer un enregistrement</h2>
</div>
<p>Veuillez remplir le formulaire ci-dessous.</p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="multipart/form-data">
<div class="form-group <?php echo (!empty($PR_err)) ? 'has-error' : ''; ?>">
<label>PR+abs</label>
<input type="text" name="PR" class="form-control" value="<?php echo $PR; ?>">
<span class="help-block"><?php echo $PR_err;?></span>
</div>
<div class="form-group <?php echo (!empty($Releve_err)) ? 'has-error' : ''; ?>">
<label>Observations inspecteurs</label>
<textarea name="Releve" class="form-control"><?php echo $Releve; ?></textarea>
<span class="help-block"><?php echo $Releve_err;?></span>
</div>
<div class="form-group <?php echo (!empty($Commentaires_err)) ? 'has-error' : ''; ?>">
<label>Commentaires</label>
<input type="text" name="Commentaires" class="form-control" value="<?php echo $Commentaires; ?>">
<span class="help-block"><?php echo $Commentaires_err;?></span>
<label>Image à télécharger : <input type="file" name="avatar" /> </label>
</div>
<input type="submit" class="btn btn-primary" value="Submit" name="submit">
<a href="index.php" class="btn btn-default">Annuler</a>
</form>
</div>
</div>
</div>
</div>
</body>
</html> |
Partager