View Full Version : PHP: Query Strings
DA Master
01-03-2003, 12:32 PM
I'm using this code for my PHP query strings
<?
$tutorials = $_GET["tutorials"]
if (($tutorials == "php") or ($tutorials == "")) {
echo ("<?php include ("tuts/php.php"); ?>");
} else if($tutorials == "perl") {
echo ("<?php include ("tuts/perl.php"); ?>");
}
?>
So when I go to tutorials.php?tutorials=php it doesn't work. Is this code OK?
Uranium-235
01-03-2003, 12:45 PM
If you're using PHP 4.1 or higher yes, if not, then no
if you're using lesser then PHP 4.1, you need to use $HTTP_GET_VARS['tutorials'] instead of $_GET['tutorials']
i don't know exactly if here's your problem but you use:
if (($tutorials == "php") or ($tutorials == "")) {
i would use:
if ($tutorials == "php" || $tutorials == "") {
..
and instead of
echo ("<?php include ("tuts/php.php"); ?>");
it would be alot simpler to simply use:
include("tuts/php.php");
but that totally depens on what you prefer yourself
(in total:
<?
$HTTP_GET_VARS['tutorials'];
if ($tutorials == "php" || $tutorials == "") {
include("php.php");
}
else if($tutorials == "perl") {
include("perl.php");
}
?>):rocker:
DA Master
01-03-2003, 02:09 PM
Thanks for the help yoda. This goes in the head of every page right?
jollyfactory
01-03-2003, 05:17 PM
Originally posted by DA Master
Thanks for the help yoda. This goes in the head of every page right?
On every page you want either a perl or php header
Justin
02-06-2003, 05:40 AM
hey im kinda new...do i put that at the top of my page, and how do i get the urls to have = signs in them??
jollyfactory
02-06-2003, 06:07 AM
I've explained in another thread here (http://www.htmlforums.com/showthread.php?threadid=21266). Here's the code anyway
<html>
<head></head>
<body>
Blah blah <br>
<?php
if ($_GET["tutorials"] == "php") || ($_GET["tutorials"] == "")) {
include ("tuts/php.php");
} else if( $_GET["tutorials"] == "perl") {
include ("tuts/perl.php");
}
?>
<br>
blah blah
</body>
</html>
first make sure your server supports PHP and then place the <?php //code ?> where you want the data to appear on the page.
and how do i get the urls to have = signs in them??
what do you mean? Please clarify :)
scoutt
02-06-2003, 09:14 AM
Originally posted by yoda
and instead of
echo ("<?php include ("tuts/php.php"); ?>");
it would be alot simpler to simply use:
include("tuts/php.php");
but that totally depens on what you prefer yourself
that was your problem DA. if you are in php mode then you don't/can't use
echo ("<?php include ("tuts/php.php"); ?>");
as that will be making it come out of php mode.
originally posted by Justin
hey im kinda new...do i put that at the top of my page, and how do i get the urls to have = signs in them??
when the user clicks on the link it will be like this
<a href="page.php?tutorial=php">Link</a>
then in page.php you have the code on this page a the very top.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.