Link to home
Start Free TrialLog in
Avatar of FairyBusiness
FairyBusinessFlag for United States of America

asked on

Whats up with my php link?

Hi, for my edit_product.php page

I have two places where you can edit things.  Categories or products, example:

http://auroriella.com/edit_product.php?edit=necklaces&product=1

http://auroriella.com/edit_product.php?edit=necklaces&silver=1

I created the links the same way, only the first one works and the second one returns to the content page!  What's it mean when a link does this??  I'm at a loss
Avatar of robertkennedy
robertkennedy
Flag of Australia image

I would need to see the code for edit_page.php to assist

The 'edit=necklaces' part of the  URL doesn't appear to be doing anything at preset. For example the following URL will take you to exactly the same page:

http://auroriella.com/edit_product.php?product=1 

Rather than &silver=1 i suspect this should be something like color=1 or color=silver depending on how you have setup the variables and name value pairs.
Sorry that should have read edit_product.php :)
Avatar of FairyBusiness

ASKER

Ok, here is my edit_product.php page

http://auroriella.com/edit_product.txt

and here is the function I used to create these menus. .. I warn you its long (haven't gone back and see what I can make re-usable)

function edit_menu($select_menu, $select_product) {
	global $table;
	$menu_result = get_menu();
	$output = "";
	// These loops output the subject names with their corresponding pages underneath them
	while ($menu = mysql_fetch_array($menu_result)) {
		$output .= "<h3><a";
		if ($menu["id"] == $select_menu['id']) { // Makes the selected menu link bold
			$output .= " class=\"selected\"";
		}
		$output .= " href=\"edit_product.php?edit=" . $menu['menu_name'] . "&menu=" . urlencode($menu["id"]) . "\">{$menu["menu_name"]}</a></h3>";	// Builds the menu links
		$products_result = get_menu_products($menu["id"]);
		$output .= "<ul>";
		while (($product = mysql_fetch_array($products_result))) {
			$output .= "<li";
			if ($product["id"] == $select_product['id'] || ($product['name'] == $table)) { // Makes the selected submenu link bold
				$output .= " class=\"selected\">";
			}
			else {
				$output .= ">";
			}
			$output .= "<a href=\"edit_product.php?edit=" . $product['name'] . "&product=" . urlencode($product["id"]) . "\">{$product["name"]}</a></li>";	// Builds the product links
			$metal_name = metal_name();
			$metal_id = metal_id();
			// Displays a side menu for the products page, the metal categories, & bolds the current selection
			if(($product["id"] == $select_product['id']) || (isset($_GET[$metal_name]) && $product['name'] == $table) || (isset($_GET['item']) && $product['name'] == $table)) {
				$metals_result = get_metals();
				$output .= "<ul>";
				while ($metal = mysql_fetch_array($metals_result)) {
					$output .= "<li";
					if ($metal["id"] == $metal_id) { // Makes the selected submenu link bold
						$output .= " class=\"selected\">";
					}
					elseif(isset($_GET['item'])) { // For item display page
						$product_metal = get_data($field='metal_id', $table);
						if($metal["id"] == $product_metal) {
						$output .= " class=\"selected\">";
						}
					}
					else {
						$output .= ">";
					}
					$output .= "<a href=\"edit_product.php?edit=" . $product['name'] . "&" . $metal["name"] . "=" . urlencode($metal["id"]) . "\">{$metal["name"]}</a></li>";	// Builds the metal links
				}
				$output .= "</ul>";
			}
		}
		$output .= "</ul>";
	}
	return $output;
}

Open in new window

I put the edit=necklaces or whatever just incase I ended up needing to know which table to use for a query.

I have three main tables for jewelry;

necklaces
earrings
bracelets

If I end up not needing to know the table name I will remove it.  but it was just a precaution.  For example if I have the table and the metal stored in the url then I can find all the fields with the metal id for silver on the necklaces table.
ASKER CERTIFIED SOLUTION
Avatar of robertkennedy
robertkennedy
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I had completely forgot about that!

You know I got that part from a tutorial I was watching a couple of weeks ago:

if(intval($_GET['product'] == 0)) {
      ob_end_clean();
      redirect_to('content.php');

Do you think its really necessary?
I gather you will be using authentication so that only certain users will have access to edit / delete products?

That part of the code doesn't really seem necessary to me however it is simple error checking so that if a malformed link is used when trying to edit a product it will capture it and not allow the user to edit a product unless all the relevant information is given. There are a few different ways you coudl probably achieve the same result and ultimately it will depend on how many users have access to eidit the products and what the likelihood is of them making a mistake.

For example think about a user manually changing the url at the top and removing one of the key/value pairs. Will your code handle this exception? Is this likely to ever happen?

They are really the decisions you need to make.

Hope I have been helpful.

Cheers
Rob
Thanks!

Hey if you want to take a stab at another one of my questions look here:

https://www.experts-exchange.com/questions/26984527/How-to-use-array-push-when-you-are-initializing-the-array-with-a-key.html?anchorAnswerId=35497390#a35497390

but just scroll down to my last comment because the other stuff is already taken care of.