How to save variables generated with Jquery in php?

0

I have a button that adds inputs onclick and I would like to be able to save or make the desired code in some for for insertion 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" />');
})
    
asked by anonymous 07.03.2018 / 17:28

2 answers

0

My question was to get the values named iframe with $_POST['iframe'] because they all had this name. My solution was to save them in% with% putting the inputs like this:

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

With array I was able to get the values and I made a simple iframe[] 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]."')");
}
    
08.03.2018 / 18:19
0

I did not quite understand your question!

If you are wanting to get data through Javascript, and save it to the Database ...

You can use Ajax, so in this way you get the values with javascript, send an ajax to a php page. This way with PHP you can retrieve the data obtained by javascript, then save it to the database with PHP.

    
08.03.2018 / 14:58