I want to store dynamic generated input fields in same column of the table with their individual values seperated by commas but using implode for the same is saving only data of first input type. i have given name of input field as an array (skill[]) so that it can store multiple value Here is my code
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
function check(skill) {
const selectedSkils = $(skill).val();
$('.techInput').each(function(i, v) {
if (selectedSkils.indexOf($(v).attr('id')) !== -1) {
$(v).removeClass('hide');
} else {
$(v).addClass('hide')
}
})
}
</script>
<style>
.hide {
display: none;
}
.techInput {
margin: 5px;
padding: 5px;
border-radius: 4px;
}
</style>
</head>
<body>
<form action="submit1.php" method="post" >
<select name="skills[]" id="skills" multiple onchange="check(this);">
<option value="css">css</option>
<option value="php">php</option>
<option value="magento">magento</option>
</select>
<div id="css" class='hide techInput'>
<label for="sel1"></label><input type="text" name="skill[]" id="selc1" placeholder='css'>
</div>
<div id="php" class='hide techInput'>
<label for="sel2"></label><input type="text" name="skill[]" placeholder='php' id="selc2">
</div>
<div id="magento" class='hide techInput'>
<label for="sel3"></label><input placeholder='magento' type="text" name="skill[]" id="selc3">
</div>
<input type="submit" name="submit" id="submit">
</form>
</body>
</html>
Although select inputs are saving in database submit1.php
<?php
require 'dbserver.inc.php';
if(isset($_POST['submit']))
{
$f_skills = mysqli_real_escape_string($conn,implode(', ', $_POST['skills']));
$f_skill = mysqli_real_escape_string($conn,implode(', ', $_POST['skill']));
$query = "INSERT INTO detail ( `f_Skills`,`f_skill`) VALUES (?,?)";
$stmtt = $conn->prepare($query);//prepared statement method
$stmtt->bind_param("ss",$f_skills,$f_skill );//binding a parameter to question mark
$stmtt->execute();
//testing purpose
echo("Reached here after executing query");
if($stmtt->affected_rows > 0)
{
echo("success");
$stmtt->close();
}
else
{
echo("fail");
}
}
else
{
echo("error occur please check");
}
?>