I have this SweetAlert (JavaScript) Code and I want to pass that Variable to my database. The Variable is result.value[0] and I want to send that to my Database. But it does not work and I don't know why....
This is my entire JavaScript Code.
<script>
$(document).ready(function () {
$('#new-btn').click(function () {
swal.mixin({
input: 'text',
confirmButtonText: 'Next →',
showCancelButton: true,
progressSteps: ['1', '2', '3']
}).queue([
{
input: 'file',
inputAttributes: {
name:"image",
class:"image",
},
title: 'Profilbild hochladen',
text: 'Empfohlen wird 1X1'
},
{
input: 'file',
title: 'Hintergrundbild hochladen',
text: 'Empfohlen wird 16X9'
},
{
title: 'Über mich',
text: ''
},
]).then((result) => {
if (result.value) {
var kuerzeltest = "mk304";
$.ajax({ type: "POST", url: "../../register/profil_update.php",
data: {"post":result.value[2], "kuerzel": kuerzeltest },
}); $.ajax({ type: "POST", url: "../../register/profil_update.php",
data: {"bild":result.value[0],"bild2":result.value[1], "kuerzel": kuerzeltest },
contentType: false,
processData: false,
});
swal(
"Super!",
"Dein Profil wurde erfolgreich aktualisiert ",
"success"
)
}
})
});
})
</script>
and this is my backend code
<?php
include_once '../../userdata.php';
//Posts in Datenbank schreiben
$kuerzel = $_POST["kuerzel"];
$bild = $_FILES['bild'];
$bild2 = $_FILES['bild2'];
$post = $_POST["post"];
$pdo = new PDO ($dsn, $dbuser, $dbpass, array('charset'=>'utf8'));
$sql = "INSERT INTO user_bilder (kuerzel, bild, bild2, post) VALUES (?, ?, ?, ?)";
$statement = $pdo->prepare($sql);
$statement->execute(array("$kuerzel", "$bild", "$bild2", "$post"));
$row = $statement->fetchObject();
header("Location: ../webpage/home.php");
?>
would be greatfull for any tips!