I'm trying to get a value of a mysql database using a php function. I have a database like this:
NAME | EMAIL | PASSWORD | OTHER
-------------------------------------------------------
example | [email protected] | password | other
-------------------------------------------------------
example2 | [email protected] | password2 | other2
and in my PHP file I've tried to use this function:
function selectUserField($email, $field, $connection){
$select_user = "SELECT '$field' FROM users WHERE email='$email' LIMIT 1";
$result = mysqli_query($connection, $select_user);
$value = mysqli_fetch_assoc($result);
return $value[$field];
}
//And I try to echo the result of the function
$connection = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
echo selectUserField("[email protected]", "name", $connection);
But as result I get only the field name and not its content (for this example I get "NAME" and not "example"). How can i do to get the content of the database cell?