$_get[]; problems

Show off new creations, get help, or just chat about all aspects of web development and design.

$_get[]; problems

Postby zeroeh on Sun Jun 01, 2008 3:38 pm

Hello, I am currently making a one page site using $_get[];. I'm just doing some basic work but I have hit a road block and I can't figure out why my $_get's arn't retrieving data from the url.

The problem is it will just go to the else statement,

Code: Select all
<?php
    $catt = $_GET[cat]
$ider = $_GET[id]
$pager = $_GET[page]
if ( catt  = 0 && ider = 1 && pager  = 1 ) {
    echo "test";
} elseif (catt  = 0 && ider = 1 && pager = 2) {
    echo "test2";
} else {
   $message =  "Sorry - The server cannot find the file or script you asked for.<br>
Please check the URL to ensure that the path is correct.";
?>
<span class="text3"> <Center> <b><?php echo $message; ?> </span></b></center>
<?php
}
?>


What I am doing to retrieve the data from the url is

index.php?cat=0&id=1&page=1


Thanks.
zeroeh
Dumpling
Dumpling
 
Joined: Thu Nov 01, 2007 6:11 pm

Re: $_get[]; problems

Postby Blink on Sun Jun 01, 2008 3:49 pm

Hmm, should they not be written like this?

Code: Select all
$catt = $_GET['cat'];
$ider = $_GET['id'];
$pager = $_GET['page'];
User avatar
Blink
Cool 'n that
Cool 'n that
 
Joined: Fri Oct 08, 2004 4:16 pm
Location: UK

Re: $_get[]; problems

Postby zeroeh on Sun Jun 01, 2008 4:13 pm

Whoops, Forgot to add them :P.

although I still receive the same problem, even after readjusting the vars.
zeroeh
Dumpling
Dumpling
 
Joined: Thu Nov 01, 2007 6:11 pm

Re: $_get[]; problems

Postby Blink on Sun Jun 01, 2008 4:17 pm

If you referring to the variables here should they not be given dollar signs?

Code: Select all
if ( $catt  = 0 && $ider = 1 && $pager  = 1 ) {
    echo "test";
} elseif ($catt  = 0 && $ider = 1 && $pager = 2) {
    echo "test2";


My PHP is quite basic so I'm just going by what I think at the moment.
User avatar
Blink
Cool 'n that
Cool 'n that
 
Joined: Fri Oct 08, 2004 4:16 pm
Location: UK

Re: $_get[]; problems

Postby zeroeh on Sun Jun 01, 2008 4:19 pm

Ah, I found my problem. I just turned globals on (Forgot they were off) and removed the get and changed the equal signs and it decided to start working.


Code: Select all
if ($cat == "0" & $id == "1" & $page == "1" ) {
    echo "test";
} elseif ($cat  == "0" & $id == "1" & $page == "2") {
    echo "tests2";
} else {
   $message =  "Sorry - The server cannot find the file or script you asked for.<br>
Please check the URL to ensure that the path is correct.";
?>
<span class="text3"> <Center> <b><?php echo $message; ?> </span></b></center>
<?php
}
?>


Thanks for the responses Blink.
zeroeh
Dumpling
Dumpling
 
Joined: Thu Nov 01, 2007 6:11 pm

Re: $_get[]; problems

Postby zombie@computer on Sun Jun 01, 2008 4:28 pm

NEVER WRITE A SINGLE LINE OF PHP WITH GLOBALS ON.
Its evil, a security risk, and will cause most scripts to fail (like phpbb, cmsses)
dont ever use it, learn to work without it. You'll thank me later.

besides that:
the and operator takes two &&. One & is a bitwise operator, which does something completely different.

quick php echoes are done with shorttags (if enabled)
Code: Select all
<php
$test="watermelon";
?>
<html>
Hi, this is a <?=$test;?> word
</html>
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Re: $_get[]; problems

Postby Jest@ on Mon Jun 02, 2008 3:47 pm

What Zombie said. register_globals MUST be off - it's only still even in PHP to allow backward compatibility with badly written php3-era scripts. In PHP6 (due to launch this year, IIRC) it'll be gone. Forever. For good. Not an option. so get used to coding without it. For your own sake!! it's a recipe for disaster.
Highlight to read:
It was earth all along
User avatar
Jest@
Veteran
Veteran
 
Joined: Mon Nov 22, 2004 1:50 am
Location: London UK

Return to Web Design & Development

Who is online

Users browsing this forum: No registered users

cron