I have a link that send the user to another page where the information showed changes based on the url parameters:
<a href="page.php?'.'name'.'='.stripslashes($row['nome']).'&'.'date'.'='.stripslashes($row['date']).'">Link to the page</a>
And I use the following SQL query to retrieve the data from a database:
$sql = "SELECT * FROM table WHERE name='".mysqli_real_escape_string($conn,$_GET['name'])."' AND date='".mysqli_real_escape_string($conn,$_GET['date'])."'";
This works if the “name” parameter contains quotes, double quotes, slashes etc. but it doesn’t if an “&” in present. How can I make it so that this & is treated as a normal character and not as a delimiter for the URL parameters?
Thanks Anthony The url is correctly encoded now, but it looks like the WHERE clause in the sql code is not working correctly. The problem happens with strings containing the ampersand character. I’ve also tried chaning the & in the database entry to %26 to make it match with the url but it’s till not working. Is there a particular way that I should store this character in the database to make it work in this case?
By the way, I just realized that there’s an error in the code I posted in the op:
$sql = "SELECT * FROM table WHERE name='".stripslashes($_GET['name'])."' AND date='".stripslashes($_GET['date'])."'";
Ok, now what I don’t understand is: why is it that things work if I leave the 3 backslashes and they don’t if I use stripslashes on the string? After all, after encoding the URL, here there’s \‘. Using stripslashes \\\’ becomes \', and in this case things don’t work