php - Using POST to get select option value from HTML form -
i have form different information. have select multiple options , want able send database in 1 or 0 / true or false. not working. code far:
              <select name="multipleselect[]" multiple>                 <option value="" disabled selected>choose 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 looking play?</label>   and php:
$esea = 0; $faceit = 0; $matchmaking = 0; foreach ( $_post['multipleselect'] $value ) {     if ( $value == 'esea' )        { $esea = 1;       }     if ( $value == 'faceit' )      { $faceit= 1;      }     if ( $value == 'matchmaking' ) { $matchmaking= 1; } }        // sätt in datan   $sql = "insert 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 code doesnt work don't know make work. wan't send 1 or 0 depending on if chose alternative or not.
your <select> multiple selectable dropdown needs array, defined name="namethatmakessense[]"
<select name="namethatmakessense[]" multiple>   this return field called $_post['namethatmakessense'] array containing 1 or more values indicating items in dropdown selected. value="" attribute of <option> tag
then need preprocess namethatmakessense array pick values selected form multi select dropdown.
$esea = 0; $esea = 0; $esea = 0; foreach ( $_post['namethatmakessense'] $value ) {     if ( $value == 'esea' )        { $esea = 1;       }     if ( $value == 'faceit' )      { $faceit= 1;      }     if ( $value == 'matchmaking' ) { $matchmaking= 1; } }      $sql = "insert users               ( profilename, profileurl, avatar, region,                 age, esea, faceit, matchmaking, textarea1 )          values (   '{$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'])}')";      
Comments
Post a Comment