title: Add data to MySQL when button is click, not when the page is loaded
body: <p>I have a page where you can add videos to your playlist. this is done by clicking on add button. </p>
  
  <p>however the problem is every-time i go to this page regardless of clinking the add button, it adds that video to yourplay list even if its already there. </p>
  
  <p>You have to have an account to use the playlist feature. the add button is visible when your are logged in, and if not legged in then you dont see the add button. </p>
  
  <p>here is my code for adding to the database:</p>
  
  <pre><code>if (isset($_SESSION['username'])){
  
  
                  echo '&lt;button type="submit" formmethod="post" formaction="video.php" onClick="Confirm(this.form)"&gt;ADD&lt;/button&gt;';
  
                  $userID = $_SESSION['username'];
                  $ID = $watch;
                  $artist = $new[0];
                  $title = $new[1];
                  $youtubeID = $code;
                  include 'opendb.php';
                  $sql = "insert into youtube_playlist (userid,youtubeID,artist,title) values ((select id from users where username = \"$userID\"),\"$youtubeID\",\"$artist\",\"$title\")";
                  $result = mysql_query($sql,$conn) or die(mysql_error());
  
              }
              //if not logged in.
              else{
                  echo "You are not logged in, you cant use the playlist feature.";
              }
  </code></pre>
  
  <p>so even when you are logged in and trying to watch a video its adds it to the playlist even if you dont want to. 
  how do you make sure that this never happens??</p>