Need help with named variable & include statement
Moderators: egami, macek, gesf
-
- New php-forum User
- Posts: 9
- Joined: Mon Apr 08, 2013 12:38 pm
Below is a partial bit of the code I am using in a php file. This particular file is called emails.php. This used to work for me:
<br>
<a href="emails.shtml">Back to the main e-mails page.</a>
<br><br>
<?php
$emno = "emails/$em.php";
include "$emno";
?>
I am declaring a variable called emno to reflect the emails directory & respective files, then a statement to include the numbered php file in the emails directory. This particular php code has worked for me for a long time. All of a sudden when I try to open one of the numbered files in the emails directory online, all I see is the "Back to the main e-mails page" message. Can anyone recommend any kind of modification I can do to the php script to get this working? I edit my html and php pages for a particular website using Dreamweaver. I have switched from Windows XP to Windows 8; could this be an issue here?
Any help is appreciated. I want the site visitors to be able to see the contents of the email files themselves, not just the statement that says return to the main emails page.
<br>
<a href="emails.shtml">Back to the main e-mails page.</a>
<br><br>
<?php
$emno = "emails/$em.php";
include "$emno";
?>
I am declaring a variable called emno to reflect the emails directory & respective files, then a statement to include the numbered php file in the emails directory. This particular php code has worked for me for a long time. All of a sudden when I try to open one of the numbered files in the emails directory online, all I see is the "Back to the main e-mails page" message. Can anyone recommend any kind of modification I can do to the php script to get this working? I edit my html and php pages for a particular website using Dreamweaver. I have switched from Windows XP to Windows 8; could this be an issue here?
Any help is appreciated. I want the site visitors to be able to see the contents of the email files themselves, not just the statement that says return to the main emails page.
-
- New php-forum User
- Posts: 9
- Joined: Mon Apr 08, 2013 12:38 pm
<?php
echo $emno
$emno = "emails/$em.php";
include "$emno";
?>
I'm assuming you meant this. I tried this and now all I get is a blank page.
echo $emno
$emno = "emails/$em.php";
include "$emno";
?>
I'm assuming you meant this. I tried this and now all I get is a blank page.
Use this code
it is also good to rewrite $emno = "emails/$em.php"; as $emno = "emails/".$em.".php";
Code: Select all
<?php
$emno = "emails/$em.php";
echo $emno;
include "$emno";
?>
-
- New php-forum User
- Posts: 9
- Joined: Mon Apr 08, 2013 12:38 pm
Sorry, but I still just get a blank page when I click the link. Adding the "echo" didn't help.
-
- New php-forum User
- Posts: 9
- Joined: Mon Apr 08, 2013 12:38 pm
$emno refers to separate php files in a directory called emails. The php file with this code is used in connection with an shtml file called "emails.shtml". The files in the emails directory are consecutively numbered. Each individual email is referred to by a link, i.e., "emails.php?em=001". Don't know how much this will help.
-
- New php-forum User
- Posts: 9
- Joined: Mon Apr 08, 2013 12:38 pm
It is. In this example, the first would be emails/001.php, then 002 and so on. Sorry for the confusion.
Maybe this will help:
Our file emails.php:
<?php
$emno = "emails/$em.php";
include "$emno";
?>
Our file emails.shtml:
<a href="emails.php?em=001">Open Letter</a>
Maybe this will help:
Our file emails.php:
<?php
$emno = "emails/$em.php";
include "$emno";
?>
Our file emails.shtml:
<a href="emails.php?em=001">Open Letter</a>
It looks like you are not collecting the "em" value. Try this code:
Code: Select all
if (isset($_GET["em"]))
{
$em = $_GET["em"];
}
else
{
echo "<br/> Unable to get value for the variable 'em'";
}
$emno = "emails/$em.php";
include "$emno";
-
- New php-forum User
- Posts: 9
- Joined: Mon Apr 08, 2013 12:38 pm
Awesome! That worked! Thanks so much!! Appreciate it!!