user6542
user6542

Reputation: 21

sql in php not returning anything

How do I see what is returned from a sql statement in php? I have the following function to get user name from mysql database and I use echo in another php to see the result but nothing shown.

function get_user_name($id_user) {
    return mysql_result(mysql_query("SELECT username FROM user WHERE id_user = '$id_user'"));
}

echo $id_user;
$a = get_user_name($id_user);
echo $a;

Can anyone help? Thanks.

Upvotes: 0

Views: 101

Answers (1)

samayo
samayo

Reputation: 16495

Are you echoing the get_user_name(); function?? OR are you even connected to your database? these are two things you need to check before, (if the problem remains) including an error handling method i.e. or die(mysql_error()) at the end of your query to find out the problem.

return mysql_result(mysql_query("SELECT id_user FROM user WHERE id_user = '$id_user'")or die (mysql_error()));

The error handling construct?? in mysql mysql_error() should output the problem in fairly understandable way, as to what is preventing your query not to be shown

Upvotes: 1

Related Questions