I'm currently facing an issue with PHP variables not being evaluated in my query, and I'm hoping someone can help me out. I have a database with user information, and I'm trying to fetch specific records based on a user-provided value.
Here's what my code looks like:
$userInput = $_POST['searchValue'];
$query = "SELECT * FROM users WHERE username = '$userInput'";
$result = mysqli_query($connection, $query);
I'm using a HTML form with the POST method to get the user input. However, whenever I try to search for a specific username, the query doesn't return any results. It seems like the PHP variable `$userInput` is not getting evaluated properly in the query.
I have checked that the `$userInput` variable is indeed receiving the correct value from the form. I have also verified that my database connection is working fine, as I can successfully fetch results without using the variable.
I'm not sure what I'm doing wrong here. Could there be a syntax error in my query? Or is there a better way to include variables in SQL queries? Any help or suggestions would be greatly appreciated!
Thanks in advance!