I've been playing around with this for 30 odd minutes now and basically been making a right fool of myself...
I want to make a function called
userInfo() that uses the users email address, stored in
$_SESSION['auth'];, to get any information required from sql. I'm using MySQLi and I'm very new to it (started this morning).
So basically, the function
config.php should create an array of that users info. When I need the username of the user I should be able to type
$userInfo['landline']; to get the landline of the user anywhere on a page that has config.php included.
Now looking at the below example from php.net I know I need an associative array. What I don't udnerstand is keeping the array alive for the pages lifespan so that I can easily display array values anywhere. I've dedited the query below to match my actual SQL query.
<?php $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); $query = "SELECT * FROM users WHERE email = '".$_SESSION['authenticated_user']."'"; $result = $mysqli->query($query); /* associative array */ $row = $result->fetch_array(MYSQLI_ASSOC); /* free result set <--- Do I just delete this? */ $result->free(); /* close connection <--- Does closing the connection destroy the retrieved values? */ $mysqli->close(); ?>
Can anyone please help?
Thanks in advance!
Edited by mmcdonald