PHP - Getting user information through $_GET

Asked

Viewed 29 times

-1

Hello, I have a leaderboard on which I want to make sure that when I click on the player’s nick to open the profile containing his information, however, I don’t know exactly how to start.

I’m trying to:

if (isset($_GET['name'])) 
{
    $query = $_GET['name'];
    $query = htmlspecialchars($query);        
    $query = mysqli_real_escape_string($connection, $query);

    $raw_results = mysqli_query($connection, "SELECT * FROM `user` JOIN `statistic` ON `user`.`uuid` = `statistic`.`uuid` LIKE '%". $query ."%'");
    $raw_resultsmedia = mysqli_query($connection, "SELECT * FROM `user` JOIN `social media` ON `user`.`uuid` = `social media`.`uuid` LIKE '%". $query ."%'");

    while($resultsmedia = mysqli_fetch_array($raw_resultsmedia) && $asd = mysqli_fetch_array($raw_results))
    {

    }
}

$query takes the right nickname, however, when it comes to taking the wrong messages. it already goes through a parameter ? name=Username, but when it is time to get the information of that particular nick, it does not respond correctly.

  • The uuid is a numeric set, so the parameter name should be the same set. P.S.: If you want to take a user’s data, it makes no sense to use LIKE. Q2: You can use multiple JOIN in a query.

1 answer

0

Hello, good night

The GET parameter type is passed to the server through the URL, so it must be present in the link, otherwise it will show that such parameter does not exist. In the link you use to redirect the user, add the name parameter (which is what you reference in the code) to the URL. Example:

<a href="profile.php?name=USERNAME">meu perfil</a>

Two other things caught my attention, first, avoid the use of spacers in the name of your tables, databases and even files, and another, the PHP Mysql connection library is already exceeded, try to replace with PHP_PDO, which is a newer one. I also recommend that you always test your queries directly in the database and without the use of variables, so that there is no error of writing or anything like, later in the code, just add the variables.

I hope I helped, hug.

  • Hello Lucas Deano, he’s already passed a parameter ? name=Username, but when it is time to get the information of that particular nick, it does not respond correctly.

  • Hello, take a look at the changes I made! I hope I’ve helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.