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
https://forums.phpfreaks.com/topic/109077-solved-why-doesnt-this-work/
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);
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.