Jump to content

[SOLVED] Why doesn't this work?


pugboy

Recommended Posts

I am creating a script to display a dropdown filled with stuff from my text file...

 

This is the code I have:

 

				<?
			$fileName = "./name.txt";
			$fh = fopen($fileName, 'r');
			$exists = file_exists($fileName);
			echo $exists;
			$nameB = fread($fh, filesize($fileName));
			echo $nameB;
			fclose($fh);
			$name = explode("\n",$nameB);
			$fileName = "./var.txt";
			$fh = fopen($fileName, 'r');
			$varB = fread($fh, filesize($fileName));
			fclose($fh);
			$var = explode("\n",$varB);
			for ( $id = 0; $id <= $maxid; $id += 1) {
			echo "<option value='$var[$id]'>$name[$id]</option>";
			}
			?>

 

A lot of the code is just for debugging, and nothing is echoed at all...

 

My directories are like this:

 

home directory

-name.txt

-var.txt

-UserCP

--add.php (The code above)

 

 

Why is nothing displayed? Do I have the file names set correctly?

Link to comment
Share on other sites

try

<?

$fileName = "../name.txt";
$fh = fopen($fileName, 'r');
$exists = file_exists($fileName);
echo $exists;
$nameB = fread($fh, filesize($fileName));
echo $nameB;
$name = explode("\n",$nameB);
fclose($fh);

$fileName = "../var.txt";
$fh = fopen($fileName, 'r');
$varB = fread($fh, filesize($fileName));
$var = explode("\n",$varB);

for ( $id = 0; $id <= $maxid; $id += 1) {
echo "<option value='$var[$id]'>$name[$id]</option>";
}
fclose($fh);
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.