I used bootstrap input-tags in my site. but I can't just handle the tags' values as they are rendered in a span tag with the same class names. I want to get values of each rendered tag and then insert into MySQL database using php and jQuery. what I have for now is:
<head>
<!-- botstrap-tags css and js -->
<link rel="stylesheet" href="bootstrap-tags/css/bootstrap-tagsinput.css" type="text/css">
<script src="bootstrap-tags/js/bootstrap-tagsinput.js"></script>
</head>
<form action="" method="post">
<div class="form-group">
<label>Tags</label>
<input type="text" name="tags" data-role="tagsinput" value="sport, politics, business">
</div>
<div class="form-group">
<input type="submit" value="add tags">
</div>
</form>
when I'm done with adding my tags, it generates tags as:
<span class="tag label label-info">
"sport"
<span data-role="remove">
::after
</span>
</span>
<span class="tag label label-info">
"poltics"
<span data-role="remove">
::after
</span>
</span>
<span class="tag label label-info">
"business"
<span data-role="remove">
::after
</span>
</span>
this is my php script
<?php
$dbhost = 'localhost:3306';
$dbuser = 'root';
$dbpass = '';
$dbname = 'web';
$link = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
if(! $link ) {
echo 'Connected failure<br>';
}
if (isset($_POST['submit'])) {
$tags=$_POST['tags'];
$sql = "INSERT INTO `tags`(`name`) VALUES ('$tags')";
if (mysqli_query($link, $sql)) {
// alert success message
echo "tags added successfully";
}
else {
echo "Error: " . $sql . "<br>" . mysqli_error($link);
}
}
?>
anyone can help? thanks