I have this ajax that shows the items chosen in the " checkbox " of the form.
$(document).ready(function(){
$('#submit').click(function(){
var languages = [];
$('.get_value').each(function(){
if($(this).is(":checked"))
{
languages.push($(this).val());
}
});
languages = languages.toString();
$.ajax({
url:"form_cadastro.php",
method:"POST",
data:{languages:languages},
success:function(data){
$('#result').html(data);
}
});
});
});
Html
<input type="checkbox" value="1" class="get_value" name="redes_sociais">
<input type="checkbox" value="1" class="get_value" name="site">
<input type="checkbox" value="1" class="get_value" name="endereco">
<button type="submit" id="submit" class="btn btn-primary">Cadastrar</button>
PHP
if(isset($_POST["languages"]))
{
echo $_POST["languages"];
}
My question is how can I enter the values of each input in the mysql database?
Mysql Structure
$sql = "INSERT INTO planos (redes_sociais, site, endereco) VALUES
('".$_POST['redes_sociais']."', '".$_POST['site']."',".$_POST['endereco']."')";