Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1] 2   Go Down

Author Topic: PHP Help Me! :D?  (Read 2454 times)

0 Members and 1 Guest are viewing this topic.
PHP Help Me! :D?
« on: January 07, 2007, 09:15:36 pm »
  • Lionfish App dev
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3456
K, I'm making a website that uses PHP to switch pages so I don't have to do a bunch of crappy little HTML pages. So for example, I'd get the the... Hoohah page by using index.php?action=hoohah. Then it includes hoohah.php from the source directory. Here's the code:

Code: [Select]
<?
   if(file_exists("source/$_GET[action].php")) {
   require("source/$_GET[action].php");
   }else{
   require("source/home.php"); //Line 37. This comment isn't actually here. Just thought I'd let you know.
   }
?>
But on the main page (i.e. index.php w/ no ?action=anything) I get this error:

Notice: Undefined index: action in /www/1111mb.com/l/i/f/lifebox/htdocs/index.php on line 37

What exactly is the problem here?
Logged
  • Lionfish Apps

Naz

Re: PHP Help Me! :D?
« Reply #1 on: January 07, 2007, 09:30:17 pm »
  • Ph34r the toast.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 374
Does home.php exist in sources?
Logged
Don't read this.
Re: PHP Help Me! :D?
« Reply #2 on: January 07, 2007, 09:32:32 pm »
  • Lionfish App dev
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3456
Yes. I forgot to mention that home.php displays perfectly fine underneath the error.
Logged
  • Lionfish Apps
Re: PHP Help Me! :D?
« Reply #3 on: January 07, 2007, 09:38:30 pm »
  • If not now, when?
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 520
The error lies in Home.php. Search there, you must.
Logged

Naz

Re: PHP Help Me! :D?
« Reply #4 on: January 07, 2007, 09:41:39 pm »
  • Ph34r the toast.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 374
Paste home.php here too if you can't find anything.
Logged
Don't read this.
Re: PHP Help Me! :D?
« Reply #5 on: January 07, 2007, 09:42:28 pm »
  • Lionfish App dev
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3456
Code: [Select]
<html>

<body bgcolor="#ffffff">
<div align="center">
<p>Welcome to Lifebox Games!<br>
<br>

We're here to bring you only the finest of fangames, and hopefully <br>

you'll agree that our site's layout is friendly and easy to use!<br>
<br>

Please contact me by using the address in the Contact area and let me know what you think about my various games. Thanks!<br>
<br>
<br>

-Moldorma; Lifebox Founder, Wanilla Co-founder</p>
</div>
</body>

</html>
There's Home.php. Nothing at fault as far as I can tell.
Logged
  • Lionfish Apps

Naz

Re: PHP Help Me! :D?
« Reply #6 on: January 07, 2007, 09:45:50 pm »
  • Ph34r the toast.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 374
You can always take the easy way out and add a @ before line 37.  No php in home.php.

It could have to do with the fact that PHP uses constant variables as a name, and issues notices whenever it happens.  Try adding single quotes around the array indexes.
Logged
Don't read this.
Re: PHP Help Me! :D?
« Reply #7 on: January 07, 2007, 09:47:51 pm »
  • Lionfish App dev
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3456
You mean just put an @ sign at the beginning of line 37? And I know that home.php has no php, but it has to be a PHP file to call it, right? :P
Logged
  • Lionfish Apps
Re: PHP Help Me! :D?
« Reply #8 on: January 07, 2007, 09:49:58 pm »
  • If not now, when?
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 520
The @ will supress any errors resulting from the "require", but I'm not sure if that is the problem here. Require usually throws fatal errors, not notices.

Code: [Select]
@require("home.php"); //Line 37. This comment isn't actually here. Just thought I'd let you know.
Logged

Naz

Re: PHP Help Me! :D?
« Reply #9 on: January 07, 2007, 09:50:28 pm »
  • Ph34r the toast.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 374
I suggest following my second direction.  @ is useful for things like MySQL queries when it really doesn't matter what you get back, but theres always a better way than surpressing the error, such as 'or'  Try surrounding array indexes with single quotes, you used an array in this you know :P
Logged
Don't read this.
Re: PHP Help Me! :D?
« Reply #10 on: January 07, 2007, 10:19:31 pm »
  • Lionfish App dev
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3456
The @ didn't work. And neither did single quotations. :P And neither did both.
Logged
  • Lionfish Apps

Naz

Re: PHP Help Me! :D?
« Reply #11 on: January 07, 2007, 11:34:22 pm »
  • Ph34r the toast.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 374
Where did you put the single quotes?  Try the @ on every line and see if it works.  If it does, start removing them until it is only on the line(s) that are errored.  Paste the one with both here.
Logged
Don't read this.
Re: PHP Help Me! :D?
« Reply #12 on: January 07, 2007, 11:56:28 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
erm ... undefined index pretty much explains the error. Undefined indexs refer to when you are attempting a access an element of a collection that does not exist, the fact that its throwing 'action' as the undefined index should pretty much tell you whats gone wrong.

Its being caused by you trying to access action element of the $_GET array, when you have not defined an action element.

The easiest solution to this is just to check if its defined (use the isset macro) or not before you try and access it.

I must admit I'm pretty suprised you haven't worked this out XD, the error message is pretty clear and consise.
Logged

Naz

Re: PHP Help Me! :D?
« Reply #13 on: January 08, 2007, 12:10:04 am »
  • Ph34r the toast.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 374
Oh god, I though action was part of the error, they really should put that in quotes >_>

Just add in a isset to check if the key exists.

I think the line number mixed me up >_>  I'm surprised I didn't realize that myself. :(
Logged
Don't read this.
Re: PHP Help Me! :D?
« Reply #14 on: January 08, 2007, 12:26:32 am »
  • If not now, when?
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 520
Yeah, I guess it fooled us all except Infinitus ;)
Logged
Re: PHP Help Me! :D?
« Reply #15 on: January 08, 2007, 01:00:14 am »
  • Lionfish App dev
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3456
It still has me fooled. I don't do PHP much. I just borrowed this from my old website which my genious friend coded. And it didn't give me any errors there. :/
Logged
  • Lionfish Apps
Re: PHP Help Me! :D?
« Reply #16 on: January 08, 2007, 01:04:49 am »
  • If not now, when?
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 520
It all depends on how the php.ini is setup. Some show errors like this, and some don't...
Code: [Select]
<?
   if(isset($_GET['action']) && file_exists("source/$_GET['action'].php")) {
   require("source/$_GET['action'].php");
   }else{
   require("source/home.php"); //Line 37. This comment isn't actually here. Just thought I'd let you know.
   }
?>

That should work, I think.
Logged
Re: PHP Help Me! :D?
« Reply #17 on: January 08, 2007, 01:20:27 am »
  • Lionfish App dev
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3456
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /www/1111mb.com/l/i/f/lifebox/htdocs/index.php on line 37

Eek!

EDIT: Got rid of the signle quotations around action and it works like a charm. Thanks Acid. ;D
« Last Edit: January 08, 2007, 01:22:10 am by Moldorma »
Logged
  • Lionfish Apps

Naz

Re: PHP Help Me! :D?
« Reply #18 on: January 08, 2007, 01:26:00 am »
  • Ph34r the toast.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 374
It all depends on how the php.ini is setup. Some show errors like this, and some don't...
Code: [Select]
<?
   if(isset($_GET['action']) && file_exists("source/$_GET['action'].php")) {
   require("source/$_GET['action'].php");
   }else{
   require("source/home.php"); //Line 37. This comment isn't actually here. Just thought I'd let you know.
   }
?>

That should work, I think.
The errors could be because there are singlequotes in a variable inside a string.  Try:
Code: [Select]
<?
   if(isset($_GET['action']) && file_exists("source/".$_GET['action'].".php")) {
   require("source/".$_GET['action'].".php");
   }else{
   require("source/home.php"); //Line 37. This comment isn't actually here. Just thought I'd let you know.
   }
?>

And are you sure that's line 37?  Every line counts.  Also, are you talking about Miles? XP
Logged
Don't read this.
Re: PHP Help Me! :D?
« Reply #19 on: January 08, 2007, 01:28:09 am »
  • Lionfish App dev
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3456
I already fixed it Naz. ;)
Logged
  • Lionfish Apps
Pages: [1] 2   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.128 seconds with 74 queries.