• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

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
0
FairyBusiness
Asked:
FairyBusiness
  • 4
  • 4
1 Solution
 
robertkennedyCommented:
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.
0
 
robertkennedyCommented:
Sorry that should have read edit_product.php :)
0
 
FairyBusinessAuthor Commented:
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

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
FairyBusinessAuthor Commented:
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.
0
 
robertkennedyCommented:
Hi,

This section of your code explains why it is redirecting to the content.php page:

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

What this piece of code means is that if the URL does not contain &product=x where x is not equal to 0 then it will automatically find this statement true and therefore redirect to content.php.

using the following url:
http://auroriella.com/edit_product.php?edit=necklaces&product=1&silver=1

shoudl resolve the issue as it inlcudes the product=x section, in this case a 1 for necklaces.
0
 
FairyBusinessAuthor Commented:
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?
0
 
robertkennedyCommented:
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
0
 
FairyBusinessAuthor Commented:
Thanks!

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

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_26984527.html#a35497390

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now