Jump to content

url addresses not matching


surreal5335

Recommended Posts

I am working on a database that sends off user entered info to a databse upon submit of the form. The problem is when this occurs preg_match() is getting weird results for its two separate string to match for a proper url route while going to a new page.

 

Currently no info is being submitted to the database.

 

My site:

 

http://royalvillicus.com/comment_board/

 

once the data is submitted I am left with this feedback:

 

$route['url'] = /^\/(?P\d+)\/delete$/

$url = posts/create

no route found

 

$route['url'] and $url are the two strings being checked for a match. This check is being done with this code:

 

function dispatcher($routes)
  {
    // $_SERVER['REQUEST_URI'] gets the URL typed in by the user
    $url = $_SERVER['REQUEST_URI'];
    // Removes Application root from URL
    $url = str_replace(DS.APP_ROOT.DS,'',$url);
    //Holds the Named Captures, $_POST Data
    $params = parse_params();
    // $_SERVER['QUERY_STRING'] - string in the url used to access the current page
    $url = str_replace('?'.$_SERVER['QUERY_STRING'], '', $url);
    //Becomes true if $route['url'] matches $url
    $route_match = false;
    // loops over $routes looking for a match
    foreach($routes as $urls => $route)
    {
      
      // sets $route_match to true
      // exits loop after match found
      if(preg_match($route['url'],$url,$matches))
      {
  // if match found appends $matches to $params
        $params = array_merge($params, $matches);
        $route_match = true;
        break;
      }
    }

 

When the data is submited from the form it links to

 

action = "<?php echo DS.APP_ROOT.DS;?>posts/create"

 

(DS.APP_ROOT.DS gets replaced with nothing using str_replace())

 

So this would explain $url being equal to "posts/create". My real problem is trying to figure out where $route['url'] got the "/^\/(?P\d+)\/delete$/" from. I realize it came from with in the array bc it is an option, but how did it get refered to that one?

 

There is a lot of code involved in this, so I am going to stop here to see what suggestions you may have as to how to diagnose the problem.

Link to comment
https://forums.phpfreaks.com/topic/197166-url-addresses-not-matching/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.