0

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...

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>

Edited by mani2604: n/a

4
Contributors
7
Replies
11
Views
7 Years
Discussion Span
Last Post by diafol
0

Is it possible you can post your entire script?

Usually i use isset for the submit and at the end of the page i put in the code for the action :) and for my form action i put instead of action="php_2.php" id put action=""

0

Is it possible you can post your entire script?

Usually i use isset for the submit and at the end of the page i put in the code for the action :) and for my form action i put instead of action="php_2.php" id put action=""

well the function GetStoreTable() is supposed to be in php_1 now.. if both the function and the submit wer in the same page this is how my code goez:-

http://pastebin.com/s5BaMUPS

0

You can use session_start() in your code to get variable in php_2 page and pass in into php_page 1..

Your php_1 file should be like this..

<?php
session_start(); // initialization to session be started
$_SESSION = $_POST; // put value from textbox into session variable

?>
<html>
<head><title>page_1</title></head>
<body>
<form action="php_2.php" method="post">
Ymax<input type="text" name="Ymax" size="15">
<input type=SUBMIT name="submit" VALUE="Submit">
</form>
</body>
</html>

Then in php_1 page you can use the value in text of php_2 by taking the value from session variable to inquiry your sql database.. The $query should be like this..

session_start();
$query = "SELECT * FROM state4 WHERE (LONG_HI < '" . $_SESSION . "'>";

hope it can help..

Edited by erik nainggolan: n/a

0

You can use session_start() in your code to get variable in php_2 page and pass in into php_page 1..

Your php_1 file should be like this..

<?php
session_start(); // initialization to session be started
$_SESSION = $_POST; // put value from textbox into session variable

?>
<html>
<head><title>page_1</title></head>
<body>
<form action="php_2.php" method="post">
Ymax<input type="text" name="Ymax" size="15">
<input type=SUBMIT name="submit" VALUE="Submit">
</form>
</body>
</html>

Then in php_1 page you can use the value in text of php_2 by taking the value from session variable to inquiry your sql database.. The $query should be like this..

session_start();
$query = "SELECT * FROM state4 WHERE (LONG_HI < '" . $_SESSION . "'>";

hope it can help..

Well actually the php_1 page just creates a image with some data overlayed from the query... we only reference the URL of php_1 in the second php page to embed it in our mapserver framework

So the thing is we do always stay on the php_2 page but somehow post data to the php_1 for the database query purposes.....

0

Well actually the php_1 page just creates a image with some data overlayed from the query... we only reference the URL of php_1 in the second php page to embed it in our mapserver framework

So the thing is we do always stay on the php_2 page but somehow post data to the php_1 for the database query purposes.....

For this case, it seems you need to embed ajax mechanism on the php2. But, the mechanism's gonna a bit slightly different based on your server configuration, If you turned off the global variable you will be required to have responseText instead of response XML on php_2.

on your php_2 you should put this...

<script type="text/javascript" language="JavaScript">
var xmlHttp = createXMLHttpRequestObject();

function createXMLHttpRequestObject(){
 var xmlHttp;

 // if running on internet xplorer
 if(windows.ActiveXObject){
   try{
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
   }
   catch(e){
       xmlHttp = false;
   }
 }
 //if running on mozilla or another browser
 else{
   try{
       xmlHttp = new XMLHttpRequest();
   }
   catch(e){
       xmlHttp = false;
   }
 }

  // return the created object or pass error message
  if(!xmlHttp)
     alert("Error creating xmlHttpRequest Object");
  else
     return xmlHttp;
}

  function reachDataPHP1(YmaxVariable){
   
   var YmaxVariable2 = YmaxVariable;
    if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
       xmlHttp.open("GET", "lib/source/php_1.php?YmaxVariable="YmaxVariable, true);
       xmlHttp.onreadystate  = handleResponse;
       xmlHttp.send(null)
    }
    else{
    // recall this function because readiness sometime is interrupted by connection
      setTimout("reachDataPHP1(" + YmaxVariable ")", 500);
    }
  }

  function handleResponse(){
     if(xmlHttp.readyState == 4){
       if(xmlHttp.status == 200){
          xmlResponse = xmlHttp.responseText; // response depends on global variable configuration
          document.getElementById("imageLocation").src = xmlResponse;
          setTimout("reachDataPHP1(" + YmaxVariable ")", 500);
       }
       else{
          alert("There is an unusual thing on the server");
       }
     }
  }

</script>

      Ymax<input type="text" name="Ymax" id="YmaxValue" size="15">

      <input type="BUTTON" name="BUTTON_FOR_PROCESS_AJAX" VALUE="Submit" onclick="javascript:reachDataPHP1(document.getElementById(\"YmaxValue\").value)"></td>

     <img id="imageLocation" width="100px" height="100px"></image>

------------------------------------------------------------------------------------------------------------------

on php_1 you have to put some additional code to accept the variable posted by your ajax script

<?php

$YMaxVariablePassedFromPage1 = $_GET['YmaxVariable'];

// and then put variable you take from php_2 on your query
$query = ("SELECT * FROM state4 WHERE (LONG_HI<'".$YMaxVariablePassedFromPage1."')");

// after that go your code until reach the object desired from database
// this object that would be passed to your ajax script in php_2 directly even if you just stay on php_1.php

echo $object_fetched_from_your_query;

?>

-----------------------------------------------------------------------------------------------------------------------------------------------------------

It's gonna little confusing if you're not familiar with javascript.. ... But i ensure you that ajax is the solution for your case.. .. . .

Edited by erik nainggolan: n/a

0

Well actually the php_1 page just creates a image with some data overlayed from the query... we only reference the URL of php_1 in the second php page to embed it in our mapserver framework

So the thing is we do always stay on the php_2 page but somehow post data to the php_1 for the database query purposes.....

Well actually the php_1 page just creates a image with some data overlayed from the query... we only reference the URL of php_1 in the second php page to embed it in our mapserver framework

So the thing is we do always stay on the php_2 page but somehow post data to the php_1 for the database query purposes.....

For this case, it seems you need to embed ajax mechanism on the php2. But, the mechanism's gonna a bit slightly different based on your server configuration, If you turned off the global variable you will be required to have responseText instead of response XML on php_2.

on your php_2 you should put this...

<script type="text/javascript" language="JavaScript">
var xmlHttp = createXMLHttpRequestObject();

function createXMLHttpRequestObject(){
 var xmlHttp;

 // if running on internet xplorer
 if(windows.ActiveXObject){
   try{
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
   }
   catch(e){
       xmlHttp = false;
   }
 }
 //if running on mozilla or another browser
 else{
   try{
       xmlHttp = new XMLHttpRequest();
   }
   catch(e){
       xmlHttp = false;
   }
 }

  // return the created object or pass error message
  if(!xmlHttp)
     alert("Error creating xmlHttpRequest Object");
  else
     return xmlHttp;
}

  function reachDataPHP1(YmaxVariable){
   
   var YmaxVariable2 = YmaxVariable;
    if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
       xmlHttp.open("GET", "lib/source/php_1.php?YmaxVariable="YmaxVariable, true);
       xmlHttp.onreadystate  = handleResponse;
       xmlHttp.send(null)
    }
    else{
    // recall this function because readiness sometime is interrupted by connection
      setTimout("reachDataPHP1(" + YmaxVariable ")", 500);
    }
  }

  function handleResponse(){
     if(xmlHttp.readyState == 4){
       if(xmlHttp.status == 200){
          xmlResponse = xmlHttp.responseText; // response depends on global variable configuration
          document.getElementById("imageLocation").src = xmlResponse;
          setTimout("reachDataPHP1(" + YmaxVariable ")", 500);
       }
       else{
          alert("There is an unusual thing on the server");
       }
     }
  }

</script>

      Ymax<input type="text" name="Ymax" id="YmaxValue" size="15">

      <input type="BUTTON" name="BUTTON_FOR_PROCESS_AJAX" VALUE="Submit" onclick="javascript:reachDataPHP1(document.getElementById(\"YmaxValue\").value)"></td>

     <img id="imageLocation" width="100px" height="100px"></image>

------------------------------------------------------------------------------------------------------------------

on php_1 you have to put some additional code to accept the variable posted by your ajax script

<?php

$YMaxVariablePassedFromPage1 = $_GET['YmaxVariable'];

// and then put variable you take from php_2 on your query
$query = ("SELECT * FROM state4 WHERE (LONG_HI<'".$YMaxVariablePassedFromPage1."')");

// after that go your code until reach the object desired from database
// this object that would be passed to your ajax script in php_2 directly even if you just stay on php_1.php

echo $object_fetched_from_your_query;

?>

-----------------------------------------------------------------------------------------------------------------------------------------------------------

It's gonna little confusing if you're not familiar with javascript.. ... But i ensure you that ajax is the solution for your case.. .. . .

0

For Ajax, ease the pain with jQuery or prototype. Fussing with the Ajax object is a headache and often ends in tears.

Here's the usual methodology:
1. 'submit' calls a js script
2. js cript passes info to (or simply calls) a php script
3. php script does its thing
4. php can return data to original js script (not always necessary)
5. js updates the page or flashes a message in response to the data returned.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.