Forum Moderators: coopster
I am trying to get a query from the adress (e.g. /index.php?query=1 )
and print it in the script
this is the portion of the script i want it to print in
<? $query ="THIS IS WHERE I WANT IT TO PRINT";
echo $query;
$query = $data->query($query);
while ($pic = $data->fetch_array($query)){?>
As you can see its very simple i just dont know how to print the query in?query
Any help would be appreciated :)
Thank You
D. Murphy
Should be something like:
$query = 'SELECT * FROM table WHERE id = ' . (int) $_GET['query'];
Oh, btw, Welcome to WebmasterWorld, D_Murphy! ;)
echo $_GET['query'];
/*if you have $query shown in the URL then you can fetch it using GET global array and if you are posting a form using POST method then use $_POST i.e POST array, if it is coming in cookies then use $_COOKIE and for sessions $_SESSION global arrays ... you need to use global arrays in fact :)
*/
btw make sure it is an integer value otherwise you can do type-casting before using it in the code using (int)
you could use ctype_digit [php.net] or is_numeric [php.net]
$query = $_GET['query'];
settype($query, 'int');echo gettype($query) . ' > ' . $query;
look at what happens if you use settype and someone put a string in the url
With settype($str, 'int') if there's a number before any char, returns just the first numbers (555), else returns 0:
$query = '555vasd45465sdas';
settype($query, 'int');
[edited by: Psychopsia at 5:46 pm (utc) on Nov. 28, 2006]