How do I use File Handlers in Sweetalert?

85 views Asked by At

I am very new to JavaScript so I am guessing, that this problem will be fairly simple for most of you guys (or at least I hope so...)

I have this SweetAlert Code. It asks the User to upload two images and one text. I am able to add the text to my database but I am struggling with the images... I know that I need to pass the Images using the File Handlers, but I don't know how...

This is my Server that I run my Code on: https://mars.iuk.hdm-stuttgart.de/~mk304/Web_Projekt/webpage/ui/sweetalert/sweetalert_eingabe.php

This is my SweetAlert2/JavaScript Code

<script>
var kuerzeltest = "mk304";
var channeltest = "3";

$(document).ready(function () {
    $('#new-btn').click(function () {

        swal.mixin({
            input: 'text',
            confirmButtonText: 'Next &rarr;',
            showCancelButton: true,
            progressSteps: ['1', '2', '3']
        }).queue([
            {
                input: 'file',
                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) {



                $.ajax({ type: "POST",  url: "../../register/profil_update.php",
                    data: {"post":result.value[2],"bild":result.value[0],"bild2":result.value[1], "kuerzel": kuerzeltest },

                });
                swal(
                    "Super!",
                    "Dein Profil wurde erfolgreich aktualisiert ",
                    "success"

                )
            }
        })
    });
})

and this is my backend code for the database

    <?php
include_once '../../userdata.php';
//Posts in Datenbank schreiben


$kuerzel = $_SESSION["kuerzel"];
$bild = $_POST["bild"];
$bild2 = $_POST["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: ../home/home.php");

?>

this is a photo of my database

my database

0

There are 0 answers