1
<h1>I LOVE YOU</h1>
  <formaction="practice.php" method="post">
    <select name="option">
      <option class="hiddenOption"></option>
      <option>I love you, too!</option>
      <option>Sorry I love someone else</option>
    </select> <br>
    <input type="submit" name="submit">
  </form>

  <?php if (isset($_POST['submit'])): ?>
    <?php
      $option = $_POST['option'];
      $op1 = "I love you, too!";
      $op2 = "Sorry I love someone else";


     if ($option == "I love you, too!") {
      $url = "https://www.youtube.com/watch?v=a7fzkqLozwA&feature=relate";
      parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
      echo $my_array_of_vars['v'];
    }
    ?>
  <?php endif; ?>

I want to link a youtube video based on what the users choose from the options. Then autoplay it on the website after the user submit their options. What is the best or effective solution to this? Thank you.

link for the first option: https://www.youtube.com/watch?v=a7fzkqLozwA , link for the second option: https://www.youtube.com/watch?v=0xgaqhe5QiM

  • I admit I don't know about PHP, but, you can redirect once a selection is done - [check this answer about how you can do this](https://stackoverflow.com/a/45706233/12511801), then open the youtube link in the same (or another) tab. Please [edit] your question by adding any error details of the current behaviour. – Marco Aurelio Fernandez Reyes Jan 19 '22 at 21:10

0 Answers0