Hi everyone...

Well i do have a mysql query in one php page(php_1) & I want to submit the variables to the query in different php page(php_2) via form action but how am I supposed to do it without redirecting to php_1..

All I need is to post the data to the first php page query so that It performs some action over there & thats all... So hoping sumone who knows ajax might helpme out with a sample code or point me in the right direction...


php_1 page :-

$query = ("SELECT * FROM state4 WHERE (LONG_HI<'".$_POST['Ymax']."')");

php_2 page:-

Ymax<input type="text" name="Ymax" size="15">
	      <input type=SUBMIT name="submit" VALUE="Submit"></td>

I dont know much about php, but first change the submit button to a normal button

<input type="button" name="submit" VALUE="Submit" onclick="sendInfo()">

and use the onclick property to call your ajax function, there are many examples of a simple ajax function on the internet.

This is the codes:
(page php_2):

<script type="text/javascript">
function sendData(){
xmlhttp=new XMLHttpRequest();
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if(xmlhttp.readyState==4 && xmlhttp.status==200){
var Ymax=document.getElementById('Ymax').value;
//in the html element <div id="forResult"></div>
//will be writen what you write with "echo" in your php file
//in this example, "Thank you for submiting Ymax"
Ymax: <input type="text" id="Ymax" size="15"><br>
<input type="button" value="Submit" onclick="sendData()">
<div id="forResult"></div>


echo "Thank you for submiting Ymax";

The var Ymax in line 11 is out of scope for xmlhttp.open in line 19.
Hence it uses in "Ymax" input box in line 24 and prints [object HTMLInputElement]

I would use JQuery:

        $(function() // on DOM loaded
            $("#btnSubmit").click(function(){ // Click handler 
                var yMax = $("#txtYmax").val(); // Get YMax value
                    'MyPhpPage.php', // Page to handle the request
                    { yMax : yMax }, // Parameters to send
                    function(result) { // Function executed when the request is completed
                    function(erro) { // Function executed when the request throws an error
                        //do something
        Ymax: <input type="text" id="txtYmax" size="15">
              <input type="button" value="Submit" id="btnSubmit">
        <div id="forResult"></div>

AleMonteiro, this post is dead, please dont bring it back from the grave.

Ymax<input type="text" name="Ymax" id="Ymax" size="15">
          <input type="button" name="submit" class="submitBtn" VALUE="Submit">
<script  type="text/javascript">

        $.post('otherPhpPage.php',{Ymax: $('#Ymax').val()},function(data){

<!--##########  In otherPhpPage.php ########  -->

echo $yMax=$_REQUEST['Ymax']; 

Result of this code will show an alert with your entered Ymas value