I am trying to create a script to upload an electronic signature to the a customers record but keep getting ID not specified error message 🙁
This is what I have come up with so far.
Code
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);
$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($_POST['name']) == null || isset($_POST['signature_img'])){
$msg = '';
}else{
$id = isset($_POST['id']) && !empty($_POST['id']) && $_POST['id'] != 'auto' ? $_POST['id'] : auto;
$stmt = $pdo->prepare('INSERT INTO skreading1 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" 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 .php?id=29 from the clients record.
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.