Added update form

This commit is contained in:
Samuel Ortion 2021-04-20 21:24:15 +02:00
parent 0ada636f57
commit bcf8e6521c
3 changed files with 125 additions and 6 deletions

View File

@ -26,7 +26,7 @@ $result = $req->fetchAll();
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?_('Explore')?> | Chiro - Canto</title> <title><?=_('Explore')?> | Chiro - Canto</title>
<link rel="stylesheet" type="text/css" href="/styles/style.css"> <link rel="stylesheet" type="text/css" href="/styles/style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head> </head>

View File

@ -3,10 +3,9 @@ ini_set('display_errors', 1);
ini_set('display_startup_errors', 1); ini_set('display_startup_errors', 1);
error_reporting(E_ALL); error_reporting(E_ALL);
session_start(); session_start();
session_reset(); $_SESSION['error_msg'] = "";
$root = realpath($_SERVER["DOCUMENT_ROOT"]); $root = realpath($_SERVER["DOCUMENT_ROOT"]);
$lang = isset($_COOKIE['lang']) ? $_COOKIE['lang'] : 'en'; require("$root/lang/gettext.php");
require("$root/lang/$lang/lang.php");
require "$root/database/credentials.php"; require "$root/database/credentials.php";
// Connect the database // Connect the database
try { try {
@ -47,7 +46,7 @@ if (isset($_GET['id'])){
if ($data = $req->fetch()){ if ($data = $req->fetch()){
?> ?>
<form action="update.php" method="post"> <form action="update.php" method="post">
<input type="hidden" name="id" value="<?=$_GET['id']?>" readonly>
<label for="file_name"><?=_('File Name')?>*</label> <label for="file_name"><?=_('File Name')?>*</label>
<input type="text" id="file_name"value="<?=$data['file_name']?>" readonly> <input type="text" id="file_name"value="<?=$data['file_name']?>" readonly>
<label for="coordinates"><?=_('Coordinates')?>*</label> <label for="coordinates"><?=_('Coordinates')?>*</label>
@ -60,7 +59,7 @@ if (isset($_GET['id'])){
<input type="text" name="recordist-name" id="recordist-name" value="<?=$data['recordist_name']?>" required> <input type="text" name="recordist-name" id="recordist-name" value="<?=$data['recordist_name']?>" required>
<label for="species"><?=_('Species')?>*</label> <label for="species"><?=_('Species')?>*</label>
<input type="text" name="species" id="species" value="<?=$data['species']?>"> <input type="text" name="species" id="species" value="<?=$data['species']?>">
<label for="subpsecies"><?=_('Subspecies')?></label> <label for="subspecies"><?=_('Subspecies')?></label>
<input type="text" name="subspecies" id="subspecies" value="<?=$data['subspecies']?>"> <input type="text" name="subspecies" id="subspecies" value="<?=$data['subspecies']?>">
<label for="make"><?=_('Recorder Manufacturer')?></label> <label for="make"><?=_('Recorder Manufacturer')?></label>
@ -70,6 +69,7 @@ if (isset($_GET['id'])){
<label for="serial"><?=_('Recorder Serial Number')?></label> <label for="serial"><?=_('Recorder Serial Number')?></label>
<input type="text" name="serial" id="serial" value="<?=$data['serial']?>"> <input type="text" name="serial" id="serial" value="<?=$data['serial']?>">
<input type="submit" value="<?=_('submit')?>">
</form> </form>
<?php <?php
} else { } else {

View File

@ -0,0 +1,119 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
$_SESSION['error_msg'] = "";
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
require "$root/lang/gettext.php";
require "$root/database/credentials.php";
// Connect the database
try {
$db = new PDO("mysql:host=$host;dbname=$database;charset=utf8",
$user,
$password,
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
} catch (Exception $e) {
die("Error : ".$e->getMessage());
}
if (isset($_POST['submit'])) {
if (isset($_POST['id'])) {
$id = $_POST['id'];
$req = $db->prepare('SELECT * FROM `records` WHERE id=:id');
$req->execute(array(
"id"=>$id
));
$data = $req->fetch();
} else {
$_SESSION['error_msg'] .= _('You did not specify any record id.');
header('Location: /explore/list');
}
if (isset($_POST['date'])) {
$date = $_POST['date'];
if ($date != $data['date']) {
$req = $db->prepare('UPDATE `records` SET date=:date WHERE id=:id');
$req->execute(array(
"id"=>$id,
"date"=>$date
));
}
}
if (isset($_POST['time'])) {
$time = $_POST['time'];
if ($time != $data['time']) {
$req = $db->prepare('UPDATE `records` SET time=:time WHERE id=:id');
$req->execute(array(
"id"=>$id,
"time"=>$time
));
}
}
if (isset($_POST['recordist-name'])) {
$recordist = $_POST['recordist-name'];
if ($recordist != $data['recordist_name']) {
$req = $db->prepare('UPDATE `records` SET recordist_name=:recordist_name WHERE id=:id');
$req->execute(array(
"id"=>$id,
"recordist_name"=>$recordist
));
}
}
if (isset($_POST['species'])) {
$species = $_POST['species'];
if ($species != $data['species']) {
$req = $db->prepare('UPDATE `records` SET species=:species WHERE id=:id');
$req->execute(array(
"id"=>$id,
"species"=>$species
));
}
}
if (isset($_POST['subspecies'])) {
$subspecies= $_POST['subspecies'];
if ($subspecies != $data['subspecies']) {
$req = $db->prepare('UPDATE `records` SET subspecies=:subspecies WHERE id=:id');
$req->execute(array(
"id"=>$id,
"subspecies"=>$subspecies
));
}
}
if (isset($_POST['make'])) {
$make = $_POST['make'];
if ($make != $data['make']) {
$req = $db->prepare('UPDATE `records` SET make=:make WHERE id=:id');
$req->execute(array(
"id"=>$id,
"make"=>$make
));
}
}
if (isset($_POST['model'])) {
$recordist = $_POST['model'];
if ($model != $data['model']) {
$req = $db->prepare('UPDATE `records` SET model=:model WHERE id=:id');
$req->execute(array(
"id"=>$id,
"model"=>$model
));
}
}
if (isset($_POST['serial'])) {
$serial = $_POST['serial'];
if ($serial != $data['serial']) {
$req = $db->prepare('UPDATE `records` SET serial=:serial WHERE id=:id');
$req->execute(array(
"id"=>$id,
"serial"=>$serial
));
}
}
header('Location: /explore/list');
} else {
$_SESSION['error_msg'] .= _('You did not submit the form.');
}
header('Location: /explore/list');
?>