Posting data via js/jQuery
<p>I am really new to Javascript and its many brilliant libraries, I find even the most simple scripts hard to perform. </p>

<p>I do want to learn this language, because it would be powerful for creating client websites, however at the moment I am trying to do something relatively simple, this is to flag a personal message on my site. There are many messages in a big list, and what I am looking at doing is when the user clicks the "Flag PM" image, it will run flag.php in the background which will change the flag field in MySQL from 0 to 1.</p>

<p>This script is all dependant on one field, that is id so I can run this through the database. Anyway, here is my code;</p>

<p><strong>flag.php</strong></p>

<pre><code> require('_inc/_core/core.php'); // inc core_funcs for sql &amp; clean
$pm_id = clean($_POST['p_id']); // create new variable, clean the post
echo "The ID for the PM is " . $pm_id;
mysql_query("UPDATE `messages` SET `flag_status` = 1 WHERE `id` = {$pm_id}"); // update the db
</code></pre>

<p><strong>JS/jQuery</strong></p>

<pre><code>     // Flag a Personal Message
$("#flagPM").submit(function(event) {
    event.preventDefault(); 
    $.post("flag.php", { p_id: pm_id } );
    alert(event);
});
</code></pre>

<p><strong>HTML handling the form</strong></p>

<pre><code>&lt;form action="#" id="flagPM"&gt;&lt;input type="hidden" id="pm_id" value="$id" /&gt;
        &lt;input type="submit" class="submit" value="FLAG" /&gt;&lt;/form&gt;
</code></pre>

<p>So there is a hidden input field named <strong>pm_id</strong> that contains what I want posted. </p>

<p>Would really appreciate some help, the Javascript is being run from an independent file that is two directory's up from flag.php</p>

<p>Thank you</p>
