I am trying to create a script which uploads an electronic signature to the customers record, I am getting the ID but am not able to create the entry on the database and there is no error message being produced in the logs, simply refreshes the page.
Here is what I have so far.
Code
<?php
include '../../main.php';
check_loggedin($pdo);
$msg = null;
$date = new DateTime();
$totay_date = $date->format('Y-m-d\TH:i:s');
$folderPath = "upload/";
$image_parts = explode(";base64,", $_POST['signature']);
$image_type_aux = explode("image/", $image_parts[0]);
$image_type = $image_type_aux[1];
$image_base64 = base64_decode($image_parts[1]);
$file = $folderPath . $name . "_" . uniqid() . '.' . $image_type;
file_put_contents($file, $image_base64);
if (isset($_GET['id'])) {
$stmt = $pdo->prepare('SELECT * FROM contacts WHERE id = ?');
$stmt->execute([$_GET['id']]);
$contact = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt = $pdo->prepare('SELECT id,username FROM accounts');
$stmt->execute();
$all_account_info = $stmt->fetchAll(PDO::FETCH_ASSOC);
if(isset($_POST['$name']) == null || isset($_POST['$file'])){
$msg = '';
}else{
$id = isset($_POST['id']) && !empty($_POST['id']) && $_POST['id'] != 'auto' ? $_POST['id'] : auto;
$stmt = $pdo->prepare('INSERT INTO esign VALUES (?, ?, ?, ?)');
$result = $stmt->execute([$id, $_GET['id'], $_POST['name'], $_POST['$file']]);
$msg = "Signature has been recorded.";
}
if (!$contact) {
exit('Help');
}
} else {
exit('No ID specified!');
}
?>
Form
<form action="add-sig.php?id=<?=$contact['id']?>" method="post">
<h1>Signature Pad</h1>
<div class="col-md-12">
<label class="form-label" for="name">Name</label> <input class="form-control" id="name" name="name" required="" type="text">
</div>
<div class="col-md-12">
<label class="" for="">Signature:</label><br>
<div id="sig"></div><br>
<textarea id="signature64" name="signature" style="display: none"></textarea>
<div class="col-12">
<button class="btn btn-sm btn-warning" id="clear">⌫Clear Signature</button>
</div>
</div><br>
<button class="btn btn-success" name="submit" type="submit">Submit</button>
</form>
</div>
Database
`id` int(11) NOT NULL,
`client_id` int(11) NOT NULL,
`name` varchar(100) NOT NULL,
`signature_img` varchar(255) NOT NULL
It loads the ID when clicking add signature and the address link looks something like add-sig.php?id=29 when accessing the page from the clients record page.
When I am in the clients record, I would like to be able to view the signature on their record.
The form converts the signature into an image file.