Search code examples
phpurlmysqlivanity

PHP returning wrong row in mysqli prepared statment


I'm trying to create vanity URL's for my website and as of now there is only one username in the database that can be referenced. My query will return the profile with the username "callmeoddie" no matter what letters are entered. The idea here is for the user to be able to type website.com/username to access the user's profile. I know that my htaccess is setup correctly and is working. This is a PHP issue.

$stmt = $db->prepare("SELECT `FirstName,`LastName`,`Username`,`RandNum` FROM `Users` WHERE `Username`=?");
$stmt->bind_param("i", $UserIdent);
$stmt->execute();
$stmt->store_result();
$num_of_rows = $stmt->num_rows;
$stmt->bind_result($FirstName, $LastName, $Username, $RandNum);
$stmt->fetch();
$stmt->close();

Solution

  • Solved my own problem.

    The $stmt->bind_param("i", $UserIdent); line was expecting a string, not an integer.

    The code is chanaged to $stmt->bind_param("s", $UserIdent);