/    Sign up×
Community /Pin to ProfileBookmark

Cant get sql to work

have this code

[code=php]
$query = “select user.allienceid from user where user.username = ‘”.$_COOKIE[‘user’].”‘”;
echo $query; #prints select user.id from user where user.name = ‘name’
$result = querydatabase ($query); #see below
$allience = mysql_result($result, 0, “allienceid”);
echo $allience; #should print 1
[/code]

this is the querydatabase ($query) function

[code=php]
function querydatabase ($query)
{
$db_host = ‘localhost’;
$db_name = ‘db_name’;
$db_user = ‘user’;
$db_pass = ‘password’;

mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name);
$result = mysql_query($query);
mysql_close();
return result;

}
[/code]

Now I know that the connection works. and when I run the query in phpmyadmin I get a value of 1.

but when I echo $allience nothing prints out can anybody figure out what I am doing wrong?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 07.2005 — Your function needs to return [b][color=red]$[/color]result[/b], not [b]result[/b].
×

Success!

Help @DARTHTAMPON spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...