Jump to content


id help!


8 replies to this topic

#1 wilkesy

    Young Padawan

  • Members
  • Pip
  • 56 posts
  • Location:South Shields UK

Posted 23 July 2005 - 05:28 PM

hi, i posted for some help, and we given a tutorial, which i read, then i went ahead with the knowledge i gained and tried to code a page! the code is below! now since it didnt work, i went back to the tutorial, and replaced some of my over ambitious items with something that should work straight off!

<?php 

if($id == 1)
{
echo "Hello World!";
}
if($id == 2)
{
echo "Goodbye World!";
}

?>

i named this page, content.php, now according to this tutorial, if i put
content.php?id=1 i will get "hello world!"

and if i put content.php?id=2 i will get "goodbye world!"...

let me know if i have gone wrong anywhere! and if not y isnt it working!?

#2 Jamie Huskisson

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 3,648 posts
  • Gender:Male
  • Location:Nottingham, UK

Posted 23 July 2005 - 05:41 PM

the correct syntax is:
if($id=="1")

as ($id==1) simply means "is this true?" (0 being false), putting "1" means "does this equal one?"

#3 wilkesy

    Young Padawan

  • Members
  • Pip
  • 56 posts
  • Location:South Shields UK

Posted 23 July 2005 - 05:50 PM

sweet! now tht wasnt in on the tutorial! ill give that one a wirl mate! ill praise u if it works!

#4 wilkesy

    Young Padawan

  • Members
  • Pip
  • 56 posts
  • Location:South Shields UK

Posted 23 July 2005 - 05:57 PM

ok well i tried

<?php 

if($id=="1")
{
echo 'Hello World!';
}
if($id=="2")
{
echo 'Goodbye World!';
}

?>
and still no joy :) im struggleing already and this is pretty simple stuff atm!

#5 Jamie Huskisson

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 3,648 posts
  • Gender:Male
  • Location:Nottingham, UK

Posted 23 July 2005 - 06:09 PM

try:
if($_GET['id']=="1")

instead, it may be your servers php settings, i dunno

#6 Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

Posted 23 July 2005 - 06:55 PM

What Jay suggested is correct (master php coder :)) but this will save some time (replacing each $id with $_GET['id'])

<?php

$id = $_GET['id'];

if($id=="1")
{
echo 'Hello World!';
}
if($id=="2")
{
echo 'Goodbye World!';
}

?>

:)

#7 wilkesy

    Young Padawan

  • Members
  • Pip
  • 56 posts
  • Location:South Shields UK

Posted 23 July 2005 - 07:21 PM

ahhh! see the old pixel2life forums do it again! thanks guys! turns out like u said its my php config! ill hav 2 change tht in due time!

cheers guys!

#8 softLearner

    Young Padawan

  • Members
  • Pip
  • 128 posts

Posted 24 July 2005 - 05:35 AM

Never enable Register_globals, as it can come as a security risk, this si why register_globals is off by default.

You best of using super_globals, which is $_GET, $_POST, $_REQUET, $_SERVER, $_SESSION etc.

#9 dEcade

    P2L Staff

  • P2L Staff
  • PipPipPipPip
  • 1,850 posts
  • Gender:Male
  • Location:Saskatoon, Saskatchewan
  • Interests:Guitar, Programming, Storm Chasing, Games (Designing and playing), Hockey, Photography

Posted 24 July 2005 - 10:00 AM

There is a lot of these questions we should just have a sticky on here saying How to do ?id=1 and then it says. There are many different ways I have my way and lots of people have there way, its just what they were told lol.

I do mine like this:

<?php
if(!$id)
{
echo 'blah blah blah';
}
if($id == '2')
{
echo 'id two';
}
if($id == '3' && level == '1')
{
echo 'id is 3 and level is one.';
}
else if($id == '3')
{
echo 'id 3';
}
?>

Well anyway glad you got it to work.

dEcade

Edited by dEcade, 24 July 2005 - 10:02 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users