xox Posted January 14, 2011 Share Posted January 14, 2011 Hello, I ran into new problem, I'm trying to figure this out for last two days, in total of 12 hours and you guys are my last hope. I've got 4 files that needs to be "connect" index.php <- contains one switch statement Here's part of it $step = (isset($_GET['action'])) ? $step = $_GET['action'] : $step = "1"; switch($step) { //index case "1": include("admin/index.php"); break; second file is located in admin/index.php <- contains navigation links, pure html Here's part of it <a href="?action=1">Home</a><br /> This is all working fine with no problems, which starts here I've got script for categories and subcategories which contains links and buttons <input type="button" name="Button" value="Remove" onClick="location='?action=delete&id=<?=$c["id"]?>'"> [<a href="?action=delete&id=<?=$c["id"]?>">Remove</a> In first index.php located outside /admin/ folder, where switch statement is I have the following code case "delete": require("admin/categories.class.php"); $categories->delete($_GET["id"]); echo '<script>alert("Removed!"); location="admin/class_categories_test.php"; </script>'; break; and when I click on "Remove" I get the following error Fatal error: Call to a member function delete() on a non-object in index.php As you may notice all functions are stored in admin/categories.class.php that's why I've require("admin/categories.class.php"); in switch statement. Regards Quote Link to comment https://forums.phpfreaks.com/topic/224464-dynamic-pages-and-linking-issues/ Share on other sites More sharing options...
Maq Posted January 14, 2011 Share Posted January 14, 2011 You need to create the categories object first. What is the class name from categories.class? Quote Link to comment https://forums.phpfreaks.com/topic/224464-dynamic-pages-and-linking-issues/#findComment-1159543 Share on other sites More sharing options...
Pikachu2000 Posted January 14, 2011 Share Posted January 14, 2011 [ot]Your ternary syntax is off a bit, although it doesn't affect the final outcome of the statement. It wouldn't be a bad idea to cast the data as integer, if that's what's expected. That may or may not matter, depending what else the value is used for. Also, as it's written currently, if the URL ends up as whatever_filename.php?action= the value of $step will be zero, which may have unintended effects. That can be countered with !empty instead of isset. [/ot] $step = !empty($_GET['action']) ? (int)$_GET['action'] : 1; Quote Link to comment https://forums.phpfreaks.com/topic/224464-dynamic-pages-and-linking-issues/#findComment-1159551 Share on other sites More sharing options...
xox Posted January 16, 2011 Author Share Posted January 16, 2011 You need to create the categories object first. What is the class name from categories.class? Class name is "categories" and it's located in categories.class.php. Hm... Not sure how to create categories object... [ot]Your ternary syntax is off a bit, although it doesn't affect the final outcome of the statement. It wouldn't be a bad idea to cast the data as integer, if that's what's expected. That may or may not matter, depending what else the value is used for. Also, as it's written currently, if the URL ends up as whatever_filename.php?action= the value of $step will be zero, which may have unintended effects. That can be countered with !empty instead of isset. [/ot] $step = !empty($_GET['action']) ? (int)$_GET['action'] : 1; Thanks for that info! Quote Link to comment https://forums.phpfreaks.com/topic/224464-dynamic-pages-and-linking-issues/#findComment-1160227 Share on other sites More sharing options...
Maq Posted January 17, 2011 Share Posted January 17, 2011 Something like: $cat = new categories(); $cat->delete($_GET["id"]); Quote Link to comment https://forums.phpfreaks.com/topic/224464-dynamic-pages-and-linking-issues/#findComment-1160766 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.