I created a function in an include file to run a query.
When I do a print_r ($mbr_profile) inside the final else statement of the function I get a print dump of the array values I want.
But upon return to my script using "return $mbr_profile;" trying to do the print_r of $mbr_profile throws an undefined variable error:
Encountered error: 8 in /home/omgma/public_html/member_community/mbr_profiles/mbr_profile_updt_form.php, line 34: Undefined variable: mbr_profile
The function call is:
function get_profile($username)
{
$conn = db_connect();
$result = $conn->query("select * from directory where directory_id = (select directory_id from users where username ='$username')");
if (!$result)
{//could not execute query
throw new Exception('<h2>Could not execute query to find the member profile!</h2><p>Error: '
.mysqli_errno($conn)
.mysqli_error($conn)
.'</p>' );
}
else if ($result->num_rows==0)
{// name not found
throw new Exception('<h2>Could not find user in database! </h2><p>Error: '
.mysqli_errno($conn)
.mysqli_error($conn)
.'</p>' );
}
else
{
$mbr_profile = $result->fetch_object();
print_r($mbr_profile);
return $mbr_profile;
}
}
And the script where I am trying to use the array is:
//now get the profile and show it
get_profile($username);
print_r($mbr_profile);
So how can I access the array from my query after I return to the script?