lundi 17 août 2020

PHP echo javascript doesnt work in if statement

So the code looks like this:

<script>
function createFolder(folder){
    $.ajax({
    url: "index.php",
    type: "POST",
    data: {'folder':folder},
    success: function(data) {
        console.log("successful post");
        }
    });
}
</script>

<?php
if(isset($_POST["folder"])){
    $folder = $_POST["folder"];
    if(!file_exists($folder)) {
        mkdir($folder);                         <--- this code runs
        echo '<script>alert("qwe")</script>';   <--- this code doesnt run 
    }
    else {
        echo '<script>alert("qwer")</script>';  <--- this code doesnt run
    }
    echo '<script>alert("qwert")</script>';     <--- this code doesnt run 
}
echo '<script>alert("qwerty")</script>';        <--- this code runs
?>

..so in the if-statement where I check the file exists the echo doesnt work, but the mkdir($folder) command runs successfully and it is a bit confusing for me. Why echo doesnt work if it in an if-statement?

Aucun commentaire:

Enregistrer un commentaire