Im trying to send a string to my database depending on the answers from a multiple select question. The question has three answers, ESEA,FACEIT and Matchmaking. Depending on the answer i want to send strings to my database. The database is set up with Varchar.
The html form for handling my multiple select question looks like this:
<select name="multipleSelect[]" multiple>
<option value="" disabled selected>Choose your option</option>
<option name="esea" value="esea">ESEA</option>
<option name="faceit" value="faceit">FaceIT</option>
<option name="matchmaking" value="matchmaking">Matchmaking</option>
</select>
<label>What are you looking to play?</label>
The code for handling the form look like this:
$esea = '';
$faceit = '';
$matchmaking = '';
foreach ( $_POST['multipleSelect'] as $value ) {
if ( $value == 'esea' ) { $esea = 'ESEA'; }
if ( $value == 'faceit' ) { $faceit= 'FACEIT'; }
if ( $value == 'matchmaking' ) { $matchmaking= 'Matchmaking'; }
}
Then i send it to my database like this:
$sql = "INSERT INTO users ( profilename,region, age, ranks, esea, faceit, matchmaking, textarea1 ) VALUES (
'{$mysqli->real_escape_string($_POST['profilename'])}',
'{$mysqli->real_escape_string($_POST['region'])}',
'{$mysqli->real_escape_string($_POST['age'])}',
'{$mysqli->real_escape_string($_POST['ranks'])}',
$esea,
$faceit,
$matchmaking,
'{$mysqli->real_escape_string($_POST['textarea1'])}')";
$insert = $mysqli->query($sql);
Unfortunately this code doesnt work. It just sends the rest of the values but not the string from the multipleSelect question. I don't know what im doing wrong?