-
Server Variables
Hey all
Need some help with some server variables....
My problem is i have a textbox on a html page called page1.html that when an sql query is placed in to the textbox that SQL query will display the relevent data on a PHP page called page2.php.
i have the page1.html pass the data using the GET method, on page2.php i want to grab the information passed over using the GET method using server variables... so far i have the following code
page2.php
Code:
<?php
$input = $_SERVER['QUERY_STRING'];
echo ("{$input}")
?>
This grabs the information that was entered in the textbox:
textarea=SELECT+*+FROM+tbl_Students+WHERE+DegreeID+%3D+1&Submit=Submit
what i want to do now is return the text to it's original form
SELECT * FROM tbl_Students WHERE DegreeID = 1
How would i do this?
thanks
-
Re: Server Variables
hey i have managed to get rid of the characters to return the string to it's original state using the following code:
Code:
<?php
$input = $_SERVER['QUERY_STRING'];
$input = str_replace('+', ' ', $input);
$input = str_replace('%3D', '=', $input);
$input = str_replace('textarea=', '', $input);
$input = str_replace('&Submit=Search', '', $input);
echo ("{$input}")
?>
nut i can imagine the code i'm using will not be the best solution to the problem can anyone suggest a better way of taking out the original variable?
-
Re: Server Variables
urldecode($_SERVER['QUERY_STRING']);
-
Re: Server Variables
cool that replaced the + and % but is there anothe method other than
$input = str_replace('textarea=', '', $input);
$input = str_replace('&Submit=Search', '', $input);
to remove the textarea= and &Submit=Search
-
Re: Server Variables
The variables passed by the Get request are in the $_GET superglobal array so you can just use:
urldecode($_GET['textarea'])
-
Re: Server Variables
this tutorial is ment to teach us how to use the server variables to grab the string and remove the characters automatically without using the POST or GET method
-
Re: Server Variables
Oh, well you didn't say that, I suggest a preg pattern would probably be simplest
urldecode(preg_replace('#textarea=(.*)&#i', '$1', $_SERVER['HTTP_REQUEST']));
Unless you can get away with $_REQUEST or $HTTP_REQUEST_VARS :)