What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » PHP Question

Pages: (3): « First « 1 2 [ 3 ] Last »
PHP Question
Author: Message:
davidpolitis
Full Member
***


Posts: 371
Reputation: 16
Joined: Aug 2006
RE: RE: PHP Question
quote:
Originally posted by Eddie
code:
<div id="content">
    <?
      $page = GET['p'];
      $llama = "./page/"."$page".".mdu";
      if(file_exists($llama) == TRUE){
          include ($llama);
      }
      else{
          include("error.php")
      }
?>
    </div>

Is returning the following error;

Parse error: parse error in C:\xampp\htdocs\vabase\main.php on line 29

Line 29 is "$page = GET['p'];"
PHP code:
<div id="content">
<?php
 $page = $_GET['p'];
 $llama = "./page/".$page.".mdu";
 if(file_exists($llama)) {
  include($llama);
 }
 else {
  include("error.php");
 }
?>
</div>


I"ll explain what was wrong with your code.
1. I changed the PHP opening to "<?php" because short tags (<?) need to be enabled on whatever server you decide to upload to.
2. Line 3 was using "GET", instead of "$_GET".
3. Where you set $llama, you had $page in quotes, unnecessarily.
4. Line 5 is using an if with file_exists. Since file_exists returns a boolean, "if(file_exists($llama))" works and is also shorter.
5. The include in your else contained no ";" (thanks for the heads up nana. Didn't notice it. XD)

Eddie, you should try find some books at the library like I did when I first started or find some e-books. You need to learn the language at least a bit before trying to make yourself some sought of system using database entries etc.

P.S. Sorry for editing my post so many times. XD

This post was edited on 04-03-2009 at 07:10 AM by davidpolitis.
04-03-2009 06:55 AM
Profile PM Find Quote Report
NanaFreak
Scripting Contest Winner
*****


Posts: 1476
Reputation: 53
32 / Male / Flag
Joined: Jul 2006
RE: PHP Question
quote:
Originally posted by davidpolitis
I changed the PHP opening to "<?php" because short tags (<?) need to be enabled on whatever server you decide to upload to.
this is not always the case, my host (hostgator) has short tags enabled by default, and really all hosts should (unless its a free host or something)
04-03-2009 07:06 AM
Profile PM Find Quote Report
davidpolitis
Full Member
***


Posts: 371
Reputation: 16
Joined: Aug 2006
RE: RE: PHP Question
quote:
Originally posted by NanaFreak
quote:
Originally posted by davidpolitis
I changed the PHP opening to "<?php" because short tags (<?) need to be enabled on whatever server you decide to upload to.
this is not always the case, my host (hostgator) has short tags enabled by default, and really all hosts should (unless its a free host or something)
While I do realise WAMPSERVER is not used for actual servers, it's default php.ini has short open tags disabled and says this:
quote:
Using short tags is discouraged when developing code meant for redistribution since short tags may not be supported on the target server.
Meh... it doesn't really matter. Everyone has their own preferences. E.g. usually I put all of my braces on new lines.

This post was edited on 04-03-2009 at 07:18 AM by davidpolitis.
04-03-2009 07:16 AM
Profile PM Find Quote Report
segosa
Community's Choice
*****


Posts: 1407
Reputation: 92
Joined: Feb 2003
RE: RE: RE: PHP Question
quote:
Originally posted by davidpolitis
quote:
Originally posted by segosa
PHP code:
if(file_exists($llama) == TRUE){
include ($llama);
}
else {
include("error.php")
}


The == TRUE part also may as well as be removed as file_exists returns a boolean value...
PHP code:
if(file_exists($llama)){
include ($llama);
}
else {
include("error.php")
}

:P

I would consider the explicit comparison to TRUE an issue of style, which is why I didn't complain about it.
The previous sentence is false. The following sentence is true.
04-03-2009 08:09 AM
Profile PM Find Quote Report
Felu
Veteran Member
*****


Posts: 2223
Reputation: 72
30 / Male / Flag
Joined: Apr 2006
Status: Away
RE: PHP Question
quote:
Originally posted by davidpolitis
quote:
Originally posted by segosa
PHP code:
if(file_exists($llama) == TRUE){
include ($llama);
}
else {
include("error.php")
}


The == TRUE part also may as well as be removed as file_exists returns a boolean value...
PHP code:
if(file_exists($llama)){
include ($llama);
}
else {
include("error.php")
}

:P
If you really care about that... Then you're just executing 1 line of code for the condition... you don't even need the curly brackets in that case :P

PHP code:
if(file_exists($llama))
    include ($llama);
else
    include("error.php");

04-03-2009 09:37 AM
Profile E-Mail PM Web Find Quote Report
davidpolitis
Full Member
***


Posts: 371
Reputation: 16
Joined: Aug 2006
RE: RE: PHP Question
quote:
Originally posted by Felu

PHP code:
if(file_exists($llama))
    include ($llama);
else
    include("error.php");


You forgot to remove the space after the first occurance of "include". :P

Anyway, using require instead of include may be something to think about...

quote:
require() is identical to include() except upon failure it will produce a fatal E_ERROR level error. In other words, it will halt the script whereas include() only emits a warning (E_WARNING) which allows the script to continue.

This post was edited on 04-03-2009 at 10:17 AM by davidpolitis.
04-03-2009 10:15 AM
Profile PM Find Quote Report
Pages: (3): « First « 1 2 [ 3 ] Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On