Hi i have SQL query problem im trying to get x from my database using an array the code below works but does not tell the SQL which user name to get x from so it just throws string.

can anyone rewrite the below code so that it includes the php variable $session->username i tried the following

$query = "SELECT `mail` FROM `users` WHERE `username` = `$session->username`";

x = being how many unread mail he/she has

<?php
if($session->logged_in){
$query = "SELECT mail FROM users ";
$result = mysql_query($query) or die(mysql_error());
$array = mysql_fetch_assoc($result);
}
?>

to call the SQL result i use

echo gettype($array['mail']);

how about:

$query = "SELECT count(`mail`) FROM `users` WHERE `username` = `$session->username`";

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.