0

My SQL structure looks like this:

ID - firstname - lastname - username - email - ect,ect,ect

I'm running this code so I can grab the entry and populate it into textboxes.

$un=$_REQUEST['un'];
$username2 =  $_SESSION['username'];
if(isset($_GET['un']))
{
    global $con;
    $query = "SELECT * FROM users WHERE username=$un";
    $result = mysqli_query($con,$query);
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) 
        {
            $id =  $row['ID'];
            $stat =  $row['status'];
            $firstname =  $row['FirstName'];
            $lastname =  $row['LastName'];
            $username =  $row['UserName'];
            $email =  $row['Email'];
            $steamname =  $row['steamname'];
            $steamid =  $row['SteamID64'];
            $rules =  $row['rules'];
            $about =  $row['about'];
            $appnotes =  $row['appnotes'];
                                    
                                    
        }
    }else{
            
        }
}
else {
    
}

This code works fabulous when I have it set to "WHERE id=$un" or "WHERE steamid64=$un" or "WHERE steamname=$un" but the moment I set it to "WHERE username=$un" the textboxes stop populating. The only entry in my database is for username "kielly" so naturally I set my url to www.websitehere.com/page.php?un=kielly (as I would page.php?un=10 if I had it set to look for the ID instead of username).

This is one of these moments where you're both confused, amazed, and angry lol. It just doesn't make sense to me how the code works perfectly for all structure names until I go to use "username"

Abra
  • 19,142
  • 7
  • 29
  • 41
Kielly32
  • 19
  • 3
  • 1
    `kielly` is a string and needs to be enclosed in quotes to be used in a query i.e. `$query = "SELECT * FROM users WHERE username='$un'";` But better yet, use a prepared statement and then you don't have to worry about whether the input is a string or a number. See [this Q&A](https://stackoverflow.com/q/60174/9473764) to understand how to use prepared statements. – Nick Jan 01 '21 at 07:44
  • Ah that makes a lot of sense actually. Thank you! – Kielly32 Jan 01 '21 at 08:10

0 Answers0