I have a form to upload items to my database. In this form I have a selection of checkboxes to give tags to the items. preferably I want to save these tags as one single string in my database, separated by a comma. However, no matter what I try, I only seem to get an error or just the final result of my checkboxes.
<form action="storeupdate.php" enctype="multipart/form-data" method="post">
<input type='checkbox' name='Tags' value='Milk' >Milk<br/>
<input type='checkbox' name='Tags' value='Sugar' >Sugar<br/>
<input type='checkbox' name='Tags' value='Cream' >Cream<br/>
<input type='checkbox' name='Tags' value='Chocolate' >Chocolate<br/>
<input type="reset"> <input type="submit" name="Submit" value="Submit"><br/>
</form>
storeupdate.php:
$Tags = mysqli_real_escape_string($conn, $_REQUEST['Tags']);
I have tried foreach loops, but they dont seem to give me any results back. When I echo the $Tags, I only get the 'highest' result that has been submitted.
If I can't even figure out how to grab the individual values, I can't even begin to work on a script to string them together before placing them in my database.
Update
Now that we have established I did wrong in the form, I am still confused in how to catch and convert this array.
$Tags[] = mysqli_real_escape_string($conn, $_POST['Tags[]']);
$tagstring = implode(",",$Tags);
echo "<br/> $_REQUEST = ";
var_dump($_POST['Tags']);
echo "<br/> $Tags = ";
var_dump($Tags);
echo "<br/> $tagstring = ";
var_dump($tagstring);
echo "<br/>";
echo "Tags= " . $tagstring . "<br/>";
returns the following: Array = array(6) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" [3]=> string(1) "4" [4]=> string(1) "5" [5]=> string(1) "6" } Array = array(1) { [0]=> string(0) "" } = string(0) "" Tags=
I need this array as a string separated by the comma in order to make the rest of my build code work, but im doing something wrong in the handling after I catch the data.
"; }' This just returns Tags[0] = Chocolate – Daniel de Ridder Aug 23 '18 at 10:02