Jump to content

[SOLVED] why wont this work?


Sesquipedalian

Recommended Posts

Why won't this display anything? There is a POST, but it doesn't work?

 

class.php:

function delete_game($type) {
 if ($type == 'do_action') {
	$filename = '../games/games/'.$_GET['game'].'.php';
	if (file_exists($filename)) {
		unlink($filename) or die ('COULD NOT DELETE FILE!');
		$_SESSION['view'] == 'echo_off';
		$linksfilename = '../games/links.php';
		include($linksfilename);
		$newcontent = str_replace(' | <a href="?act=games/'.$_GET['game'].'">'.strtoupper($_GET['game']).'</a>', '', $content);
		if ($handle = fopen('linksfilename', 'w')) {
			if (fwrite($handle, $newcontent)) {
				echo '<h1>Game Deleted</h1><center>Success, <b>'.$_GET['game'].'</b> has been deleted.</center>';
				include('links.php');
			} else {
				echo '<h1>Error</h1><Center>Could not write to links.php</center>';
				include('links.php');
			}
		} else {
			echo '<h1>Error</h1><center>Could not open links.php</center>';
			include('links.php');
		}
	} else {
		echo '<h1>Error</h1><Center>File does not exist.</center>';
	}
}	
}

 

 

and in homepage.php:

if ($_POST) {
$login->delete_game('do_action');
}

Link to comment
https://forums.phpfreaks.com/topic/83933-solved-why-wont-this-work/
Share on other sites

you are using variables in your function that

are not defined in the function, try making

them globals, example:

 

<?php
$variable = 'test';

function willWork(){
global $variable;

echo $variable;
}

function wontWork(){

echo $variable;
}

willWork();
echo '<br><br><br>';
wontWork();

// See the difference?
?>

what variables aren't being defined?

 

I realized i accidentally did $_SESSION['view'] == 'echo_off' instead of $_SESSION['view'] = 'echo_off'...

 

also, $content is located inside of the file.

 

the thing is, if i put an echo 'this'; in the function, it doesn't even echo it... so i think it has something to do with the part in homepage.php.. but it doesn't make sense.

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.