title: Executing a php script in javascript?
body: <p>I'm trying to run a quick php script when users leave my website, and also pass a variable from my javascript to php but i'm not quite sure how to include the php file and pass it a var. But it's not actually running the php script. any ideas?</p>
  
  <p>(the javascript gets the username from an external activity function, and i know that works i tested the var on an alert and its there.)</p>
  
  <p>My JavaScript:</p>
  
  <pre><code>&lt;script language="javascript" type="text/javascript"&gt;
  
              var username = null;
  
              function GetUsername(usernameff)
              {
                  username = usernameff;
              }
  
              window.onbeforeunload = function () 
              {
  
              if (username != null)
              {
  
              &lt;?php include("scripts/RemoveUserOnDisconnect.php?username=username");?&gt;
              }
  
              }
  
  
              &lt;/script&gt;
  </code></pre>
  
  <p>My RemoveUserOnDisconnect.php File:</p>
  
  <pre><code>&lt;?php
      mysql_connect("mysql.mysql.com", "username", "password");
      mysql_select_db("my_db");
      mysql_query("DELETE FROM my_table WHERE username = '$username'");         
  ?&gt;
  </code></pre>