function and php
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/6559868/update-database-info-with-onclick-button">Update database info with onclick button</a>  </p>
</blockquote>



<p>I have a onclick button which calls a function with php inside of it to query a database. The code works fine separately, but together, it does nothing. After looking through some answers it says I have to place the query database code into a separate PHP file, and somehow call that file on the users onclick ? Is that the best option, and if so, can anyone provide an example of how I would call the PHP database lookup file from an onclick button ? Thanks in advance. </p>

<pre><code>&lt;div onClick="newUser();"
style="position:absolute;display: block; cursor:pointer; top: 100px; left: 600px;"&gt;
&lt;img src="assets/invite.png"&gt;
&lt;/div&gt;



&lt;head&gt;
&lt;script type="text/javascript"&gt;
&lt;?php       
function newUser(){
// Make a MySQL Connection
$me = json_decode(@file_get_contents('https://graph.facebook.com/me?access_token=' . $cookie['access_token']));
$uid = $me-&gt;id;
echo "$uid";

$hostname="";
$username="";
$password="";
$dbname="mpsuserdata";
$usertable="userdata";
$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($dbname, $connection) or die ("Could not connect");
mysql_query("INSERT INTO userdata 
(id, name, startdate, enddate, shop) VALUES('11111111' , 'UK', '$startdate' , '$enddate' , 'test' ) ") 
or die(mysql_error());  
echo "Data Inserted!";
            }
?&gt;
 &lt;/script&gt; 
</code></pre>
