SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
-
Aug 28, 2001, 10:34 #1
- Join Date
- Aug 2000
- Location
- Thailand
- Posts
- 4,810
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
I must be missing something obvious.
Code:$userq = "SELECT real_name FROM users WHERE user_name='$PHP_AUTH_USER' "; $user = mysql_query($userq); echo "<P><font color=\"purple\" face=\"arial\" size=\"-2\">Welcome, $user </font></p>";
. The PHP_AUTH_USER variable is present and recognised, but when run, the echo reads "Welcome, Resource id #3" .
What am I doing wrong??
Be gentle, I'm venturing beyond hand holding script land.....
H~The Artist Latterly Known as Crazy Hamster~
922ee590a26bd62eb9b33cf2877a00df
Currently delving into Django, GIT & CentOS
-
Aug 28, 2001, 10:48 #2
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
$user only holds a result pointer to the query, you need to extract the data from the query before tyring to print it. You have several options at this point. Here is the quickest and easiest way to d oit, I'll let you explore more and figure out a suitable way for your needs.
PHP Code:$userq = "SELECT real_name
FROM users
WHERE user_name='$PHP_AUTH_USER' ";
$user = mysql_query($userq);
$row = mysql_fetch_array($user);
print "<P><font color=\"purple\" face=\"arial\" size=\"-2\">Welcome, ".$row['real_name'] ."</font></p>";
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Aug 28, 2001, 10:50 #3
- Join Date
- Mar 2001
- Location
- Southern California, USA
- Posts
- 1,181
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hello,
You can not display the whole table users like that.After the mysql_query, you need to use mysql_fetch_array in a while loop to display any record (row) or any field in a row that you want.
John
Oops! Freddy is faster than meLast edited by johnn; Aug 28, 2001 at 10:53.
-
Aug 28, 2001, 14:30 #4
- Join Date
- Aug 2000
- Location
- Thailand
- Posts
- 4,810
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Excellent - thanks guys
~The Artist Latterly Known as Crazy Hamster~
922ee590a26bd62eb9b33cf2877a00df
Currently delving into Django, GIT & CentOS
-
Aug 28, 2001, 15:14 #5
- Join Date
- Aug 2000
- Location
- Thailand
- Posts
- 4,810
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
hmmm - that option gives me a parsing error on the line:
$userq*=*"SELECT*real_name
yet no changes have been made...doh - I'm feeling thick tonight!~The Artist Latterly Known as Crazy Hamster~
922ee590a26bd62eb9b33cf2877a00df
Currently delving into Django, GIT & CentOS
-
Aug 28, 2001, 15:20 #6
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
We'll probably need to see the code you are using and the surrounding lines of code to determine what the parse error is being caused by. The code should be okay, I think its probably something right around it that is casing the error, please show some code.
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Aug 28, 2001, 15:39 #7
- Join Date
- Aug 2000
- Location
- Thailand
- Posts
- 4,810
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:<?php
// File Name: access.php
// Check to see if $PHP_AUTH_USER already contains info
if (!isset($PHP_AUTH_USER)) {
// If empty, send header causing dialog box to appear
header('WWW-Authenticate: Basic realm="Private. Unauthorised use prohibited"');
header('HTTP/1.0 401 Unauthorized');
exit;
} else if (isset($PHP_AUTH_USER)) {
// If not empty, check the database for matches
// connect to MySQL
mysql_connect("myhost", "user", "password")
or die ("Unable to connect to database. Please contact the webmaster");
// select db
mysql_select_db("auth")
or die ("Unable to select database.");
// Query db
$sql = "SELECT *
FROM users
WHERE user_name='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query($sql);
// Get number of rows in $result. 0 if invalid, 1 if valid.
$num = mysql_numrows($result);
if ($num != "0") {
// get real name
$userq*=*"SELECT*real_name
*****FROM*users
*****WHERE*user_name='$PHP_AUTH_USER'*";
// put real name in a variable
$user*=*mysql_query($userq);
//extract data from real name
$row*=*mysql_fetch_array($userq);
// display message
print*"<P><font color=\"purple\" face=\"arial\" size=\"-2\">Welcome, ".$row['real_name']*."</font></p>";
} else {
header('WWW-Authenticate: Basic realm="Private. Unauthorised use prohibited"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required. If you are an authorised user, please contact <b>Me</b> ';
exit ;
}
}
?>
The authorisation part works fine, and like I said, with the other method, it displayed the first part of the echo ok, just not the user name.
Damn, I thought I was getting the hang of all this~The Artist Latterly Known as Crazy Hamster~
922ee590a26bd62eb9b33cf2877a00df
Currently delving into Django, GIT & CentOS
-
Aug 28, 2001, 15:49 #8
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well I rewrote the brunt of your code and took out one unneeded query. You already have the real_name from the first query. I think I got your variables change back okay, as I put mine in to test it. Make sure all your tablenames and field names are okay.
PHP Code:<?php
// File Name: access.php
// Check to see if $PHP_AUTH_USER already contains info
if (!isset($PHP_AUTH_USER)) {
// If empty, send header causing dialog box to appear
header('WWW-Authenticate: Basic realm="Private. Unauthorised use prohibited"');
header('HTTP/1.0 401 Unauthorized');
exit;
}
else if (isset($PHP_AUTH_USER)) {
// If not empty, check the database for matches
// connect to MySQL
mysql_connect("localhost", "", "")
or die ("Unable to connect to database. Please contact the webmaster");
// select db
mysql_select_db("auth")
or die ("Unable to select database.");
// Query db
$sql = "SELECT * FROM users WHERE username='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query($sql);
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
// display message
print "<P><font color=\"purple\" face=\"arial\" size=\"-2\">Welcome, ".$row['real_name'] ."</font></p>";
}
else {
header('WWW-Authenticate: Basic realm="Private. Unauthorised use prohibited"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required. If you are an authorised user, please contact <b>Me</b> ';
exit ;
}
}
?>Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Aug 29, 2001, 02:25 #9
- Join Date
- Aug 2000
- Location
- Thailand
- Posts
- 4,810
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Thanks again Freddy, its still not playing but I'll persevere!
~The Artist Latterly Known as Crazy Hamster~
922ee590a26bd62eb9b33cf2877a00df
Currently delving into Django, GIT & CentOS
Bookmarks