How to save variables generated with Jquery in php?

Asked

Viewed 32 times

0

I have a button that adds inputs onclick and I would like to be able to save or effect the desired code in some for for entry into the database.

This is the code onclick

$("#add_iframe").click(function(){
    var lengt = $('.thumb').length;
    var tao = lengt + 1;
    $("#list_iframes").append('<label>Iframe '+tao+'</label><input type="text" placeholder="Insira o Iframe do Youtube Aqui" class="form-control thumb" name="iframe" />');
})

1 answer

0


My question was to take the values with the name iframe with $_POST['iframe'] because everyone had that name. My solution was based on keeping them in a array putting inputs like this:

<input type="text" placeholder="Insira o Iframe do Youtube Aqui" class="form-control thumb" name="iframe[]" />

With the iframe[] I was able to take the values and I made a simple for in php to insert them 1 to 1 in the database:

$count = count($_POST['iframe']);
for($i=1;$i < $count;$i++){
    $insert=mysqli_query($db, "INSERT INTO tabela(iframe) VALUES ('".$_POST['iframe'][$i]."')");
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.