473,382 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

PHP Include code displaying wrong error file

I have the following script but the page does not load. It always loads the error page.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.          if ($c !="") {
  3.              include ("content".$c.".php");
  4.          } else {
  5.             include ("content4.8.php");
  6.         }
  7.        ?>
Aug 9 '08 #1
9 1779
dlite922
1,584 Expert 1GB
I have the following script but the page does not load. It always loads the error page.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.          if ($c !="") {
  3.              include ("content".$c.".php");
  4.          } else {
  5.             include ("content4.8.php");
  6.         }
  7.        ?>
I'm assuming content4.8.php is the "error page".

just before the if statement write die(var_dump($c));

it will stop the script and tell you what type of variable $c is and what's in it.

Your problem is most likely elsewhere.

Make sure $c always gets set to something.



Dan
Aug 9 '08 #2
I added the script and i get following error

Parse error: syntax error, unexpected '$' in E:\inetpub\vhosts\mywebsite.com\httpdocs\i\index.p hp on line 48

line 48 is where i put the script.

so what else can be the problem
Aug 10 '08 #3
Atli
5,058 Expert 4TB
The problem revolves around the $c variable. It is most likely not being set properly. Please post the code that sets the $c variable.

To find out if your $c variable's value is what you would expect it to be, print it as the code is executed.
Like Dan suggested; you can do that by using the var_dump function in the line before the if statement.

Make sure the syntax is correct!
If you get parse errors, like the one you showed in your last post, the syntax is incorrect. If your having problems with it, post it here so we can take a look.
Aug 10 '08 #4
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <!-onMouseover Link CSS Script-c Dynamic Drive (www.dynamicdrive.com). For full source code, installation instructions, 100's more DHTML scripts, and Terms Of Use, visit dynamicdrive.com--><style><!--a:hover{color:ffffff; background-color:0066ff; }--></style>
  4. <meta http-equiv="Page-Enter" content="blendTrans(Duration=1.0)">
  5. <title>Impact international</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=EUC-JP">
  7. <!-- Fireworks MX Dreamweaver MX target.  Created Thu Aug 14 16:48:00 GMT+0900 (???? (?W?€??)) 2003-->
  8. <!--Special Effects upon page enter credit- Dynamic Drive (www.dynamicdrive.com) For full source code, installation instructions, 100's more free DHTML Scripts, and Terms Of Use, visit dynamicdrive.com-->
  9.  
  10. <script language="JavaScript1.2" src="navi.js"></script>
  11. <script language="JavaScript1.2" src="mm_menu.js"></script>
  12. <link href="base.css" rel="stylesheet" type="text/css">
  13. <link href="text.css" rel="stylesheet" type="text/css">
  14. <link href="product.css" rel="stylesheet" type="text/css">
  15. <link href="footer.css" rel="stylesheet" type="text/css">
  16. <link href="menu.css" rel="stylesheet" type="text/css">
  17. </head>
  18. <body bgcolor="#ffffff" link="#000000" vlink="#000000" alink="#000000"  onLoad="MM_preloadImages('image-top-header/top-header_r2_c4_f2.gif','image-top-header/top-header_r2_c6_f2.gif','image-top-header/top-header_r2_c8_f2.gif','image-top-header/top-header_r2_c12_f2.gif','image-top-header/top-header_r2_c14_f2.gif','image-top-header/top-header_r2_c16_f2.gif')">
  19. <p class="copyright"> 
  20.   <script language="JavaScript1.2">mmLoadMenus();</script>
  21. </p>
  22. <?php require("menu.php"); ?>
  23. <table width="800" border="0" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
  24.   <tr> 
  25.     <td width="161" valign="top" bordercolor="#FFFFFF" bgcolor="#FFFFFF" class="gray-back-left" > 
  26.  
  27.   <p>&nbsp;</p>
  28.       <?php
  29.                   die(var_dump(c$));
  30.                   if ($c != "") {
  31.                      include("content".$c.".php");
  32.                   } else {
  33.                      include("content4.11.4.php");
  34.                   }
  35.                ?>
  36.       </td>
  37.   </tr>
  38. </table>
  39. <?php require("footer.php"); ?>
  40. </body>
  41. </html>
  42.  
This is the whole page.

wbr
Aug 10 '08 #5
Atli
5,058 Expert 4TB
I'm kind of get the feeling your not even paying attention to what you are doing...

The die() line you added contains the most basic of errors. If you were really looking for it, you should be able to spot it without any problems. (Not to mention that Dan posted the correct syntax earlier).

And that code doesn't contain anything that is meant to set the $c variable. What is that variable supposed to be? Where is it getting it's value from?

P.S.
Please post all code examples inside [code] tags.
Thanks.
Aug 10 '08 #6
i am new in this so i need more help.

i received this page and was asked to correct it.

It seems that the main page links to this page and the c$ will the content required. I think the c$ value should come from address bar. So it seems that there is no command to get the c$ i.e. why the default page appears.

typical address will be

www.mywebsite.com/index.php?c=4.1


wbr
Aug 10 '08 #7
...
typical address will be

www.mywebsite.com/index.php?c=4.1
...
the url address "www.mywebsite.com/index.php?c=4.1" means that your php files ("index.php")
are using the "HTTP GET" method using parameter "c" that had the value "4.1"

now, you can retrieve the "c" value ("4.1") to your "$c" variable using the "$_GET[par]" variable to your "$c" variable.
you can change par with the GET parameter (in this case: "c")
so it goes like

$c = $_GET["c"];

now your "$c" variable has value and var.type...

o yeah, also you can remove the "die(var_dump())" line since it's purpose is only to stop the codes and collect the "$c" value and var type.

sorry if my English is not very fluent... because I'm still learning 'how-to-use' that language... LoL

thx

.dee.
Aug 10 '08 #8
Atli
5,058 Expert 4TB
i am new in this so i need more help.

i received this page and was asked to correct it.

It seems that the main page links to this page and the c$ will the content required. I think the c$ value should come from address bar. So it seems that there is no command to get the c$ i.e. why the default page appears.

typical address will be

www.mywebsite.com/index.php?c=4.1


wbr
Ok. For the record, your parse error was caused by you mixing up the variable name.
Variable names start with a dollar-sign ($), followed by the name of the variable.
So your c$ variable should have been $c.

As to the original problem. I'm guessing that this code you were asked to fix was written for an old version of PHP, like PHP4.

In PHP4 (and earlier) HTTP request variables would be automatically created for you to use in your code. (see the register_globals directive).
That is; using a URL like this: "index.php?c=4.1"
the value of c, in this case 4.1, would be put into the $c variable automatically.

In PHP5, however, this feature was disabled due to security reasons.
Now you will have to fetch them via the $_GET super-global, as the previous poster suggested.
Aug 10 '08 #9
Yes

Tks for the help. With the GET command, was able to get the $c and now the page works perfectly.

As mentioned earlier by posts, the site was created for php4.1 whereas the server is php4.4.7. So with the get command, the page is properly functioning.

wbr
Aug 11 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: bjam | last post by:
Hi, today I was able to abstract out into a separate xsl file a template that I specifically perform a call templates for, this worked with import no problem. However, when trying to do the same...
6
by: Christopher | last post by:
What is the syntax for including files from another directory? In my case I want to include a file called "error.h" which lies in a directory called "support" which is a directory inside the...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
6
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file =...
9
by: Eric Lindsay | last post by:
I can't figure how to best display little snippets of shell script using <pre>. I just got around to organising to bulk validate some of my web pages, and one of the problems occurs with Bash...
5
by: Viken Karaguesian | last post by:
Hello all, I've used the SSI Include command successfully in the past to include frequently used files that are based within my own site. However, what if I was to use a file located in a...
5
by: Tio | last post by:
I have project in MFC(vc++) . There are files and classes: classes:dialog1,dialog2,aaa,bbb ---------------------- main.cpp --------------------- #include "mainfrm.h" #include "dialog1.h"...
1
by: escort | last post by:
I am trying to include a file in my existing asp file. I am using business vista and I am getting following error This error (HTTP 500 Internal Server Error) means that the website you are...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.