Home > OS >  my select options is not taking value at time of form submission
my select options is not taking value at time of form submission

Time:09-18

at the click of submit nothing happens

  • made just a simple dropdown box with select so i can fetch the value of it with post method but i am not getting what is wrong with the code*

this the PHP code

{
$option = ISSET($_POST['genre']) ? $_POST['genre'] : false;
if ($option) {
   echo HTML entities($_POST['genre'], ENT_QUOTES, "UTF-8");
} else {
  echo "task option is required";
  exit; 
}
}

this is the html code

    <from method="post" action="file name">
        <select name="genre" id="genre" style="margin:8px;">
              <option selected disabled value="">Select genre</option>
              <option value="Action">Action</option>
              <option value="drama">Drama</option>
              <option value="sci-fi">Sci-fi</option>
              <option value="horror">Horror</option>
              <option value="romance">Romance</option>
              <option value="comedy">Comedy</option>
            </select>
            <input type="submit">
        </input>
    </from >

CodePudding user response:

You have some spelling mistakes, try this one:

<form method="post" action="action.php">
    <select name="genre" id="genre" style="margin:8px;">
      <option selected disabled value="">Select genre</option>
      <option value="Action">Action</option>
      <option value="drama">Drama</option>
      <option value="sci-fi">Sci-fi</option>
      <option value="horror">Horror</option>
      <option value="romance">Romance</option>
      <option value="comedy">Comedy</option>
    </select>
    <input type="submit">
  </form>

action.php

if (isset($_POST['genre'])) {
  echo $_POST['genre'];
} else {
  echo 'Task option is required!';
  exit;
}
  • Related