Jump to content


Photo

small query, an easy one


  • Please log in to reply
10 replies to this topic

#1 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 25 August 2006 - 10:28 AM

I have this code here :
<?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;

?>

And I get this result :

technicalResource id #2

Shouldn't I get :

technical3

technical being my username and 3 being my ID

#2 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 25 August 2006 - 10:31 AM

think u have to use mysql_fetch_arry:

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

I don't need your script, I'll try to write it myself

#3 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 25 August 2006 - 10:49 AM

I prefer mysql_fetch_assoc()

<?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"];
}

Tell me the problem, I will try tell you the solution

#4 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 25 August 2006 - 10:57 AM

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

#5 radalin

radalin
  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 25 August 2006 - 11:02 AM

well use something like:
$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'];
}

Roy Simkes
Yet Another Parkyeri Developer

#6 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 25 August 2006 - 11:20 AM

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?

#7 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 25 August 2006 - 01:55 PM

var_dump your $row variable to see what is available.

#8 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 25 August 2006 - 02:19 PM

he means use somethig like

print_r($row);
Tell me the problem, I will try tell you the solution

#9 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 25 August 2006 - 03:14 PM

OK this is my code now :
<?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);
?>

Which output's :

technical

#10 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 25 August 2006 - 03:22 PM

try print_r($row) within the while loop
Tell me the problem, I will try tell you the solution

#11 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 25 August 2006 - 03:24 PM

Sorry but still no joy, it still outputs the same




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users