Prevent redirect on form submission and use the POST variables in php
<p>I am working on a messaging system for a networking website wherein I want to use the data that the user enters. Like if the user enters 'Andy' as the recipient I want the php mechanism to use the $_POST['recipient'] variable to retrieve the id of that user and conduct a lookup rather than just going into a javascript function and terminating. I want the javascript function which actually sends the message to get called after the user clicks another button. I am new to PHP and don't understand the inner workings that well. I have given a small sample code below that is similar to mine but easier on the eyes.</p>

<pre><code>&lt;form&gt;
To:&lt;input type="text" id=rec"&gt;
&lt;input type="submit" value="confirm" id="confirm" name="confirm"&gt;
&lt;button type="button" id="sub1" onclick="sendPM()"&gt;Submit&lt;/button&gt;
&lt;/form&gt;
&lt;--some mysql look ups using $_POST['rec'] which copies values from the table into the
php variables and stores it in hidden HTML fields to be accessed later by the
sendPM() function--&gt;
$('#sub1').click(function sendPM(){.......}
</code></pre>
