&符号后的子字符串丢失[重复]

This question already has an answer here:

$mystring = "DTI ORIENTATION: CONSUMER PROTECTION & LEMON LAW";

After doing this,

$mystring = htmlspecialchars("DTI ORIENTATION: CONSUMER PROTECTION & LEMON LAW");

I'm now getting an echo of just "DTI ORIENTATION: CONSUMER PROTECTION". Even if I removed the htmlspecialchars after, the string is different now.

The words after the & sign are missing along with it. What just happened? I just want to make the & sign to be included in my string to be used in mysqli_query. Please enlighten me on this one. Thank you.

code from file1.php:

$(".t_title").click(function(){
            var title = $(this).data("title");
            var training_date = $(this).data("tdate");

            location.href = "viewTrainingAttendees.php?title=" + title + "&tdate="+ training_date; 
        });

code from viewTrainingAttendees.php:

<?php 
                        $ttitle = $_GET['title'];
                        echo $ttitle;

                     ?>
</div>

& has special meaning in a query string, it marks the start of the next key=value pair.

If you want to represent it as data, you have to percent encode it.

Use encodeURIComponent() on any plain text string you are inserting into a URL.

Better yet, use the URL API to construct query strings instead of mashing strings together. (You'll need a polyfill for old browsers).

var url = new URL(location.href);
url.pathname = "viewTrainingAttendees.php";
url.searchParams = new URLSearchParams();
url.searchParams.append("title", "DTI ORIENTATION: CONSUMER PROTECTION & LEMON LAW");
url.searchParams.append("tdate", "example example");
console.log(url.href);

</div>