<?php
function searchDatabase($key, $value)
{
$key = $key;
$query = "SELECT * FROM user_data WHERE username='$value'";
$result = mysqli_query(loadDatabase(), $query);
$numRows = mysqli_num_rows($result);
if ($numRows > 0)
{
return true;
}
else
{
return false;
}
}
?>
So I am using this code to search through my database to reveal a match on a key/value pair, but $key doesn't find the correct column in my database when passed into the query function. If I replace it with the word username, it matches fine. Is it a type issue? I am not explicitly stating its type so I can search other columns with the same function.
username: varchar(40)
$key = $key;must be a mistake? replaceusernameby$key.$query = "SELECT * FROM user_data WHERE username='$value'";should be$query = "SELECT * FROM user_data WHERE username='".$value."'";