Sesquipedalian Posted January 1, 2008 Share Posted January 1, 2008 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'); } Quote Link to comment https://forums.phpfreaks.com/topic/83933-solved-why-wont-this-work/ Share on other sites More sharing options...
Northern Flame Posted January 1, 2008 Share Posted January 1, 2008 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? ?> Quote Link to comment https://forums.phpfreaks.com/topic/83933-solved-why-wont-this-work/#findComment-427139 Share on other sites More sharing options...
Sesquipedalian Posted January 1, 2008 Author Share Posted January 1, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/83933-solved-why-wont-this-work/#findComment-427140 Share on other sites More sharing options...
Northern Flame Posted January 1, 2008 Share Posted January 1, 2008 make $_GET['game'] a global and the same for $_SESSION['view'] Quote Link to comment https://forums.phpfreaks.com/topic/83933-solved-why-wont-this-work/#findComment-427142 Share on other sites More sharing options...
Sesquipedalian Posted January 1, 2008 Author Share Posted January 1, 2008 actually. thanks, but i got it to work.. Quote Link to comment https://forums.phpfreaks.com/topic/83933-solved-why-wont-this-work/#findComment-427148 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.