I have a form where i get some different information. But then i have a Select with multiple options and i want to be able to send this to the database in 1 or 0 / true or false. But it is not working. This is my code so far:
<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>
And this is my php:
$esea = 0;
$faceit = 0;
$matchmaking = 0;
foreach ( $_POST['multipleSelect'] as $value ) {
if ( $value == 'esea' ) { $esea = 1; }
if ( $value == 'faceit' ) { $faceit= 1; }
if ( $value == 'matchmaking' ) { $matchmaking= 1; }
}
// Sätt in dataN
$sql = "INSERT INTO users ( steamid, profilename, profileurl, avatar, region, age, ranks, esea, faceit, matchmaking, textarea1 ) VALUES (
'{$mysqli->real_escape_string($_POST['steamid'])}',
'{$mysqli->real_escape_string($_POST['profilename'])}',
'{$mysqli->real_escape_string($_POST['profileurl'])}',
'{$mysqli->real_escape_string($_POST['avatar'])}',
'{$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);
I know that this code doesnt work but i don't know what to do to make it work. I wan't to send a 1 or a 0 depending on if the chose the alternative or not.