dpot
This commit is contained in:
1 parent
3e30ce1897
commit
4dfd0737cd
1 file changed
+97
-40
+97
-40
@@ -3,56 +3,91 @@
|
||||
require_once "config.php";
|
||||
|
||||
// Define variables and initialize with empty values
|
||||
$name = $address = $salary = "";
|
||||
$name_err = $address_err = $salary_err = "";
|
||||
$vokabel = $stammform = $art = $flexion = $uebersetzung = $lektion =$kommentar = "";
|
||||
$vokabel_err = $stammform_err = $art_err = $flexion_err = $uebersetzung_err = $lektion_err =$kommentar_err = "";
|
||||
|
||||
|
||||
// Processing form data when form is submitted
|
||||
if(isset($_POST["id"]) && !empty($_POST["id"])){
|
||||
// Get hidden input value
|
||||
$id = $_POST["id"];
|
||||
|
||||
// Validate name
|
||||
$input_name = trim($_POST["name"]);
|
||||
if(empty($input_name)){
|
||||
$name_err = "Please enter a name.";
|
||||
} elseif(!filter_var($input_name, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z\s]+$/")))){
|
||||
$name_err = "Please enter a valid name.";
|
||||
// Validate vokabel
|
||||
$input_vokabel = trim($_POST["vokabel"]);
|
||||
if(empty($input_vokabel)){
|
||||
$vokabel_err = "Vokabel eingeben.";
|
||||
} else{
|
||||
$name = $input_name;
|
||||
$vokabel = $input_vokabel;
|
||||
}
|
||||
|
||||
// Validate address address
|
||||
$input_address = trim($_POST["address"]);
|
||||
if(empty($input_address)){
|
||||
$address_err = "Please enter an address.";
|
||||
// Validate stammform
|
||||
$input_stammform = trim($_POST["stammform"]);
|
||||
if(empty($input_stammform)){
|
||||
$stammform_err = "Bitte Stammform eintragen.";
|
||||
} else{
|
||||
$address = $input_address;
|
||||
$stammform = $input_stammform;
|
||||
}
|
||||
|
||||
// Validate salary
|
||||
$input_salary = trim($_POST["salary"]);
|
||||
if(empty($input_salary)){
|
||||
$salary_err = "Please enter the salary amount.";
|
||||
} elseif(!ctype_digit($input_salary)){
|
||||
$salary_err = "Please enter a positive integer value.";
|
||||
// Validate art
|
||||
$input_art = trim($_POST["art"]);
|
||||
if(empty($input_art)){
|
||||
$art_err = "Bitte Wortart eingeben.";
|
||||
} else{
|
||||
$salary = $input_salary;
|
||||
$art = $input_art;
|
||||
}
|
||||
|
||||
// Validate flexion
|
||||
$input_flexion = trim($_POST["flexion"]);
|
||||
if(empty($input_flexion)){
|
||||
$flexion_err = "Bitte Flexion eingeben.";
|
||||
} else{
|
||||
$flexion = $input_flexion;
|
||||
}
|
||||
|
||||
// Validate uebersetzung
|
||||
$input_uebersetzung = trim($_POST["uebersetzung"]);
|
||||
if(empty($input_uebersetzung)){
|
||||
$uebersetzung_err = "Bitte Übersetzung eingeben.";
|
||||
} else{
|
||||
$uebersetzung = $input_uebersetzung;
|
||||
}
|
||||
|
||||
// Validate lektion
|
||||
$input_lektion = trim($_POST["lektion"]);
|
||||
if(empty($input_lektion)){
|
||||
$lektion_err = "Bitte Lektion eingeben.";
|
||||
} else{
|
||||
$lektion = $input_lektion;
|
||||
}
|
||||
|
||||
// Validate kommentar
|
||||
$input_kommentar = trim($_POST["kommentar"]);
|
||||
if(empty($input_kommentar)){
|
||||
$kommentar_err = "Bitte Tipp eingeben.";
|
||||
} else{
|
||||
$kommentar = $input_kommentar;
|
||||
}
|
||||
|
||||
|
||||
// Check input errors before inserting in database
|
||||
if(empty($name_err) && empty($address_err) && empty($salary_err)){
|
||||
if(empty($vokabel_err) && empty($stammform_err) && empty($art_err)
|
||||
&& empty($flexion_err) && empty($uebersetzung_err) && empty($lektion_err) && empty($kommentar_err) ){
|
||||
// Prepare an update statement
|
||||
$sql = "UPDATE employees SET name=?, address=?, salary=? WHERE id=?";
|
||||
|
||||
$sql = "UPDATE vokabeln SET vokabel=?, stammform=?, art=?, flexion=?, uebersetzung=?, lektion=?, kommentar=? WHERE id=?";
|
||||
|
||||
if($stmt = mysqli_prepare($link, $sql)){
|
||||
// Bind variables to the prepared statement as parameters
|
||||
mysqli_stmt_bind_param($stmt, "sssi", $param_name, $param_address, $param_salary, $param_id);
|
||||
mysqli_stmt_bind_param($stmt, "sssssssi", $param_name, $param_stammform, $param_art, $param_flexion, $param_uebersetzung, $param_lektion, $param_kommentar, $param_id);
|
||||
|
||||
// Set parameters
|
||||
$param_name = $name;
|
||||
$param_address = $address;
|
||||
$param_salary = $salary;
|
||||
$param_id = $id;
|
||||
$param_vokabel = $vokabel;
|
||||
$param_stammform = $stammform;
|
||||
$param_art = $art;
|
||||
$param_flexion = $flexion;
|
||||
$param_uebersetzung = $uebersetzung;
|
||||
$param_lektion = $lektion;
|
||||
$param_kommentar = $kommentar;
|
||||
|
||||
// Attempt to execute the prepared statement
|
||||
if(mysqli_stmt_execute($stmt)){
|
||||
@@ -77,7 +112,7 @@ if(isset($_POST["id"]) && !empty($_POST["id"])){
|
||||
$id = trim($_GET["id"]);
|
||||
|
||||
// Prepare a select statement
|
||||
$sql = "SELECT * FROM employees WHERE id = ?";
|
||||
$sql = "SELECT * FROM vokabeln WHERE id = ?";
|
||||
if($stmt = mysqli_prepare($link, $sql)){
|
||||
// Bind variables to the prepared statement as parameters
|
||||
mysqli_stmt_bind_param($stmt, "i", $param_id);
|
||||
@@ -96,8 +131,8 @@ if(isset($_POST["id"]) && !empty($_POST["id"])){
|
||||
|
||||
// Retrieve individual field value
|
||||
$name = $row["name"];
|
||||
$address = $row["address"];
|
||||
$salary = $row["salary"];
|
||||
$stammform = $row["stammform"];
|
||||
$art = $row["art"];
|
||||
} else{
|
||||
// URL doesn't contain valid id. Redirect to error page
|
||||
header("location: error.php");
|
||||
@@ -144,19 +179,41 @@ if(isset($_POST["id"]) && !empty($_POST["id"])){
|
||||
<p>Please edit the input values and submit to update the employee record.</p>
|
||||
<form action="<?php echo htmlspecialchars(basename($_SERVER['REQUEST_URI'])); ?>" method="post">
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input type="text" name="name" class="form-control <?php echo (!empty($name_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $name; ?>">
|
||||
<span class="invalid-feedback"><?php echo $name_err;?></span>
|
||||
<label>Vokabel</label>
|
||||
<input type="text" name="vokabel" class="form-control <?php echo (!empty($vokabel_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $vokabel; ?>">
|
||||
<span class="invalid-feedback"><?php echo $vokabel_err;?></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Address</label>
|
||||
<textarea name="address" class="form-control <?php echo (!empty($address_err)) ? 'is-invalid' : ''; ?>"><?php echo $address; ?></textarea>
|
||||
<span class="invalid-feedback"><?php echo $address_err;?></span>
|
||||
<label>Stammform</label>
|
||||
<textarea name="stammform" class="form-control <?php echo (!empty($stammform_err)) ? 'is-invalid' : ''; ?>"><?php echo $stammform; ?></textarea>
|
||||
<span class="invalid-feedback"><?php echo $stammform_err;?></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Salary</label>
|
||||
<input type="text" name="salary" class="form-control <?php echo (!empty($salary_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $salary; ?>">
|
||||
<span class="invalid-feedback"><?php echo $salary_err;?></span>
|
||||
<label>Wortart</label>
|
||||
<input type="text" name="art" class="form-control <?php echo (!empty($art_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $art; ?>">
|
||||
<span class="invalid-feedback"><?php echo $art_err;?></span>
|
||||
</div>
|
||||
$vokabel = $stammform = $art = $flexion = $uebersetzung = $lektion =$kommentar = "";
|
||||
|
||||
<div class="form-group">
|
||||
<label>lexion</label>
|
||||
<input type="text" name="flexion" class="form-control <?php echo (!empty($flexion_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $flexion; ?>">
|
||||
<span class="invalid-feedback"><?php echo $flexion_err;?></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Übersetzung</label>
|
||||
<input type="text" name="uebersetzung" class="form-control <?php echo (!empty($uebersetzung_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $uebersetzung; ?>">
|
||||
<span class="invalid-feedback"><?php echo $uebersetzung_err;?></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Lektion</label>
|
||||
<input type="text" name="lektion" class="form-control <?php echo (!empty($lektion_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $lektion; ?>">
|
||||
<span class="invalid-feedback"><?php echo $lektion_err;?></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Tipp</label>
|
||||
<input type="text" name="kommentar" class="form-control <?php echo (!empty($kommentar_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $kommentar; ?>">
|
||||
<span class="invalid-feedback"><?php echo $kommentar_err;?></span>
|
||||
</div>
|
||||
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
|
||||
<input type="submit" class="btn btn-primary" value="Submit">
|
||||
|
||||
Reference in new issue
Block a user