Jump to content

Archived

This topic is now archived and is closed to further replies.

scottybwoy

small query, an easy one

Recommended Posts

I have this code here :
[code]
<?php

$domain_user = explode("\\", $_SERVER['LOGON_USER']);
$user = $domain_user[1];
echo $user;

$AUTH_DB_NAME = 'mri_sql';
$AUTH_DB_TBL    = 'users';

mssql_connect("localhost,1433", "user", "pass", "") or
die("Failed Connection");
mssql_select_db("$AUTH_DB_NAME") or
die ("cannot connect to database");

$result = mssql_query("SELECT USER_ID FROM users WHERE uNAME = '" . $user . "' AND ACTIVE = '1'");

echo $result;

?>
[/code]

And I get this result :

technicalResource id #2

Shouldn't I get :

technical3

technical being my username and 3 being my ID

Share this post


Link to post
Share on other sites
think u have to use mysql_fetch_arry:

[code]
while($row = mysql_fetch_array($result))
  {
  echo $row['yourow'];
  echo "<br />";
  }
[/code]

Share this post


Link to post
Share on other sites
I prefer mysql_fetch_assoc()

[code]
<?php
$query = "SELECT USER_ID FROM users WHERE uNAME = '".$user."' AND active = '1'");
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
$user_id = $row["USER_ID"];
}[/code]

Share this post


Link to post
Share on other sites
maybe, that didn't return anything except technical.  How am I supposed to know the row number ($row['yourow']) when what I am after is the user ID from the row containing the user name.

Tried both and they return the same, only the user name

Thanks though

Share this post


Link to post
Share on other sites
well use something like:
[code]
$query = "SELECT * FROM users where uName = '$user' AND active = 1";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
if ($row[uName] == $user)
$idImLookingFor = $row['user_id'];
}
[/code]

Share this post


Link to post
Share on other sites
Still no joy, same result.  My active column is set to BIT but when viewed shows TRUE of FALSE values, if I put AND active = TRUE in my query it doesn't like it, but shouldn't 1 return the same as TRUE?

Share this post


Link to post
Share on other sites
var_dump your $row variable to see what is available.

Share this post


Link to post
Share on other sites
OK this is my code now :
[code]
<?php

$domain_user = explode("\\", $_SERVER['LOGON_USER']);
$user = $domain_user[1] . "<br />";
echo $user;

$AUTH_DB_NAME = 'mri_sql';
$AUTH_DB_TBL    = 'users';

mssql_connect("localhost", "1433", "user", "pass") or
die("cannot connect");
mssql_select_db("$AUTH_DB_NAME") or
die ("cannot connect to database");

$query = "SELECT * FROM users where uName = '$user' AND active = 1";
$query = stripslashes($query);
$result = mssql_query($query);
while($row = mssql_fetch_assoc($result)){
if ($row[uName] == $user)
$idImLookingFor = $row['user_id'];
}

print_r($row);
?>
[/code]

Which output's :

technical

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.