Hi everyone, first post here so please excuse if i miss something.
I am trying to build a function that queries from a MySQL database. The code is as follows:
function findGender($username){
global $conn;
$q = "SELECT gender FROM users WHERE username=$username";
$result = mysql_query($q,$conn);
return $result;
}
I want to use this function to return the gender of a person in the database, so i can display a list of questions based upon what gender they are.
The code for where i call the function is as follows:
<?php
session_start();
include("includelist.php");
$logged_in=checkLogin();
$username=$_SESSION['username'];
$gender=findGender($username);
echo ("Gender is" . "$gender");
Thats from the top of the .php page concerned. includelist.php is the file that contains all my functions. the checkLogin() function obviously checks whether the user is logged in and then we move to the gender. I want the function to return the result of the MySQL query and store it in the $gender variable which i will use to test against, it will either be Male or Female (obviously :p )
The echo statement is merely as a test atm to check that it works.
Currently, when the page is parsed by the server and shown in the browser, it says at the top of the page 'Gender is' followed by blank space, and then the rest of the page underneath.
Is there anything anyone can see wrong firstly with the syntax (im guessing not because i dont get any errors showing) or whether im missing any code for this sort of statement.
If there is any other code you need to look at, please let me know and i shall post it.
Thanks a lot
James