I got this code below to work but I am wondering If there is a better way to do this. It makes the URL look sloppy even with just the two variables called in this example. I like my URLs to look clean if possible and I am wondering if the way I am creating the custom link is dangerous or not.
In this example I really haven’t done any type of sanitization I was just getting it to work as quickly as possible. Basically I have a database that has different businesses listed in different categories and sub categories the user selects a main category and a sub category from a drop down list.
The user is then directed to a page that has a list of all of those businesses as links each one unique so that when they click on it only the information in the database about that business shows up on a template page all pages have an identical layout only the content changes unique to the business. You can see where if I was to pass more then a couple variables the URL would get extremely long and ridiculous to copy paste and share with others.
<?php
require 'DB.php';
require 'functions.php';
session_start();
session_is_registered(myusername);
$mainCat = $_POST['thing'];
$subCat = $_POST['subCats'];
echo $mainCat;
echo "<br>" . $subCat;
try{
$stmt = $conn->prepare('SELECT * FROM `CLL_businesses` WHERE `bCatID` = :bCategory AND `sCatID` = :sCategory');
$stmt->bindValue(':bCategory', $mainCat);
$stmt->bindValue(':sCategory', $subCat);
$stmt->execute();
} catch (PDOException $e){
echo 'Connection failed: ' . $e->getMessage();
}
while($row = $stmt->fetch())
{
$name1 = trim($row['name']);
$name = $row['name'];
$logo = $row['logo'];
$bCatID = $row['bCatID'];
$sCatID = $row['sCatID'];
$username = $row['username'];
$website = $row['website'];
echo "<br>" . "<a href=" ."http://test.com/test/new/test12.php?string1=".$name1 . "&string2=" . $logo . ">" . $name ."</a>";
}
?>
Test12.php
<?php
$name = $_GET['string1'];
$logo = $_GET['string2'];
echo $name;
echo "<br>" . $logo;
?>
I solved it by only adding one string to the url