skip to Main Content

I’m very newbie to this, so let me explain the issue:

I have a cashback script, the retailer title is stored in the database, my links looking like that:

example.com/view_retailer.php?id=232

I want to change that to /view_retailer?title=retailer-title

I can’t figure why its not working, I have on my DB the columns retailer_id, title and retailer_url. Retailer_url is empty.

if (!function_exists('GetRetailerLink')) {
    function GetRetailerLink($retailer_id, $retailer_title = "") {
        $retailer_id = (int)$retailer_id;

        $retailer_link = SITE_URL."view_retailer.php?id=".$retailer_id;
        return $retailer_link;

In php page view_retailer:

if (isset($_GET['id']) && is_numeric($_GET['id']))
    {
        $retailer_id = (int)$_GET['id'];
    }
    else
    {       
        header ("Location: index.php");
        exit();
    }

I played already around with the code below but this is not working -> shop not found.

if (!function_exists('GetRetailerLink')) {
    function GetRetailerLink($retailer_id, $retailer_title = "") {
        $retailer_id = (int)$retailer_id;

        $retailer_link = SITE_URL."view_retailer.php?title=".$retailer_title;
        return $retailer_link;

and

if (isset($_GET['title']) && is_numeric($_GET['title']))
                {
                    $retailer_title = (int)$_GET['title'];
                }
                else
                {       
                    header ("Location: index.php");
                    exit();
                }

How can I solve this problem? Thanks for helping me!


Thank you for the proposed solutions

I tried it now with

if (!function_exists('GetRetailerLink')) {
    function GetRetailerLink($retailer_id, $retailer_title = "") {
        $retailer_id = (int)$retailer_id;

        $retailer_link = SITE_URL."view_retailer.php?title=".$retailer_title;
        return $retailer_link;

and

if (isset($_GET['title']) && is_string($_GET['title']))
{
    $retailer_title = (string)$_GET['title'];
}
else
{       
    header ("Location: index.php");
    exit();
}

also tried it with

if (isset($_GET['title']))
            {
                $retailer_title = (int)$_GET['title'];
            }
            else
            {       
                header ("Location: index.php");
                exit();
            }

Unfortunately, that doesn’t fix the problem either -> Shop not found.

2

Answers


  1. You will have to remove is_numeric($_GET['title']) in your code.

    is_numeric($_GET['title']) will check if the variable is a number or a numeric string.

    Login or Signup to reply.
  2. Perhaps you can try removing is_numeric? Since title is a character string, that will return false always.

    if (isset($_GET['title']))
                {
                    $retailer_title = $_GET['title'];
                }
                else
                {       
                    header ("Location: index.php");
                    exit();
                }
    

    Hope this works for you 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search