Jump to content

Dynamic pages and linking issues


xox

Recommended Posts

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

 

Link to comment
Share on other sites

[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;

Link to comment
Share on other sites

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!

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.