Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
window.addEventListener('DOMContentLoaded', () => {
fetchEntries();
});
document.querySelector('#form').addEventListener('submit', (e) => {
e.preventDefault();
const formData = new FormData(e.target);
fetch('submit.php', {
method: 'post',
body: formData
})
.then(response => response.json())
.then(data => {
displayEntry(data);
})
.catch(error => {
console.error('Error:', error);
window.location.reload();
});
});
function displayEntry(entry) {
const imageHtml = entry.image_path ? `<img src="${entry.image_path}" alt="Image" style="max-height:30px; max-width:30px;">` : '';
const entryHtml = `
<div>
<strong>${entry.name}</strong>: ${entry.message}
${imageHtml}
<div>Timestamp: ${entry.timestamp}</div>
</div>`;
document.querySelector('.guestbook').insertAdjacentHTML('beforeend', entryHtml);
}
function fetchEntries() {
fetch('fetchEntries.php')
.then(response => response.json())
.then(data => {
data.forEach(entry => {
displayEntry(entry);
});
})
.catch(error => {
console.log('Error:', error);
});
}