SitePoint Sponsor |
|
User Tag List
Results 1 to 25 of 25
Thread: having problems,need help BAD
-
Oct 23, 2005, 23:24 #1
- Join Date
- Oct 2005
- Posts
- 12
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
having problems,need help BAD
I'm working on setting up a game script that I have used in the past on a couple other servers and had no problems with it on them. But now on this server I am having problems logging in.
No problems occur during registration, and the actual login process, just when the header.php file is accessed on this line
PHP Code:$stat = mysql_fetch_array(mysql_query("select * from players where user='$user' and pass='$pass'"));
if (empty ($stat[id])) {
print "Invalid login.";
exit;
}
Like I said, I've never had problems with this PREMADE script before in the past on other servers, and its the EXACT same script I used before, just lost everything on my computer and had to start over on a new server.
BTW, current server PHP version: 4.3.10
any help would really be appreciated.
-
Oct 23, 2005, 23:29 #2
- Join Date
- Aug 2003
- Location
- Manchester, UK
- Posts
- 4,007
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
$stat[id] will be producing a Notice:
Notice: Use of undefined constant id - assumed 'id'
You should really quote it, like, $stat['id'] but i doubt that's the root of your problem. Does this version provide any clues?
PHP Code:$query = "select * from players where user='$user' and pass='$pass'";
echo 'DEBUG: $query<br />';
$res = mysql_query($query) or die(mysql_error())
$stat = mysql_fetch_array($res);
if (empty($stat['id'])) {
die('Invalid Login.');
}
-
Oct 23, 2005, 23:33 #3
- Join Date
- Oct 2005
- Posts
- 12
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
tried adding the single quotes to the $stat[id] and that did nothing.
what do you mean by "Clues"?
-
Oct 23, 2005, 23:35 #4
- Join Date
- Aug 2003
- Location
- Manchester, UK
- Posts
- 4,007
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Clues as in it should output what the query is so you can check it looks ok and if there's any sql syntax problems it will tell you .. basically it should let you know what's happening. If there's no unusual output then it suggests the problem lies elsewhere.
-
Oct 23, 2005, 23:46 #5
- Join Date
- Oct 2005
- Posts
- 12
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:<?php include("config.php"); session_start(); ?>
<?php
if (!session_is_registered("user") || !session_is_registered("pass")) {
print "Sesion has expired.";
exit;
}
$stat = mysql_fetch_array(mysql_query("select * from players where user='$user' and pass='$pass'"));
if (empty ($stat['id'])) {
print "Invalid login.";
exit;
}
$ctime = time();
mysql_query("update players set lpv=$ctime where id=$stat[id]");
$ip = "$HTTP_SERVER_VARS[REMOTE_ADDR]";
mysql_query("update players set ip='$ip' where id=$stat[id]");
mysql_query("update players set page='$title' where id=$stat[id]");
?>
-
Oct 23, 2005, 23:53 #6
- Join Date
- Aug 2003
- Location
- Manchester, UK
- Posts
- 4,007
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Add the debugging stuff i posted above, it will probably show you the problem. I'm guessing you've written this with register_globals On and now they're (quite rightly) Off so the vars you expect to be set no longer will be. Add the debugging, then we'll no longer have to guess what the problem is .. it will present itself
-
Oct 24, 2005, 00:12 #7
- Join Date
- Oct 2005
- Posts
- 12
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
where should I add your code at?
where ever I add it I get this error "Parse error: parse error, unexpected T_VARIABLE in /home/emcsbutv/public_html/game/header.php on line 21"
and line 21 is "$stat = mysql_fetch_array($res);"
oh, and I didn't write this, it camestraight from the zip like this, all I changed was user="$user" because I didnt want people to login with email addresses.
-
Oct 24, 2005, 00:15 #8
- Join Date
- Aug 2003
- Location
- Manchester, UK
- Posts
- 4,007
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sorry, i missed the ; of this line:
$res = mysql_query($query) or die(mysql_error()) <-- needs a ;
Where you have:
PHP Code:$stat = mysql_fetch_array(mysql_query("select * from players where user='$user' and pass='$pass'"));
if (empty ($stat['id'])) {
print "Invalid login.";
exit;
}
PHP Code:$query = "select * from players where user='$user' and pass='$pass'";
echo 'DEBUG: $query<br />';
$res = mysql_query($query) or die(mysql_error());
$stat = mysql_fetch_array($res);
if (empty($stat['id'])) {
die('Invalid Login.');
}
-
Oct 24, 2005, 00:19 #9
- Join Date
- Oct 2005
- Posts
- 12
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
DEBUG: $query
Invalid Login.
-
Oct 24, 2005, 00:21 #10
- Join Date
- Aug 2003
- Location
- Manchester, UK
- Posts
- 4,007
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
*sigh* Sorry, i'm tired and making mistakes.
echo 'DEBUG: $query<br />';
should be:
echo 'DEBUG: '.$query.'<br />';
-
Oct 24, 2005, 00:22 #11
- Join Date
- Oct 2005
- Posts
- 12
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hey it's no problem, man, I really appreciate the help your giving me.
-
Oct 24, 2005, 00:23 #12
- Join Date
- Oct 2005
- Posts
- 12
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok here we go
DEBUG: select * from players where user='myusername' and pass='mypassword'
Invalid Login.
-
Oct 24, 2005, 00:25 #13
- Join Date
- Aug 2003
- Location
- Manchester, UK
- Posts
- 4,007
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
And are they the correct login details? i.e if you run that query direct in mysql (via phpMyAdmin or whatever) does it return a result ok?
-
Oct 24, 2005, 00:28 #14
- Join Date
- Oct 2005
- Posts
- 12
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Your SQL query has been executed successfully (Query took 0.0227 sec)
SQL query:
SELECT *
FROM players
WHERE user = 'myusername'
AND pass = 'mypassword'
LIMIT 0 , 30
I'd say thats a yes, otherwise it would of returned an error, correct?
-
Oct 24, 2005, 00:30 #15
- Join Date
- Aug 2003
- Location
- Manchester, UK
- Posts
- 4,007
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No, it's a valid query, but there might be no results, which would be an invalid login.
It just sounds like that user doesn't exist in the database with that password. One last check you can do is after this line:
$stat = mysql_fetch_array($res);
add:
var_dump($stat);
-
Oct 24, 2005, 00:32 #16
- Join Date
- Oct 2005
- Posts
- 12
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
DEBUG: select * from players where user='myusername' and pass='mypassword'
bool(false) Invalid Login.
-
Oct 24, 2005, 00:36 #17
- Join Date
- Aug 2003
- Location
- Manchester, UK
- Posts
- 4,007
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
*shrug* Just seems like there is no user in your database with the username and password you gave.
-
Oct 24, 2005, 00:41 #18
- Join Date
- Oct 2005
- Posts
- 12
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I just noticed that the password that is coming up in the debug, is not my USERNAME password, its the password for $cpass in the config.php file . . .
-
Oct 24, 2005, 01:46 #19
- Join Date
- Oct 2005
- Location
- Sydney, Australia
- Posts
- 95
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Change the variable '$pass' to something different and then try. I.E $userpass.
-
Oct 24, 2005, 11:03 #20
- Join Date
- Jan 2005
- Location
- Maine
- Posts
- 40
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
allready tried that Anne, didnt do anything.
I noticed something though when I setup a new database, I can't remember the exact error, and won't be able to post it until I get home later, cause I'm on a work computer and can't login to me cpanel right now.
But the error was something like my_sql_connect(failed) or something like that. I'll post the exact error later.MK3DESIGN!
AFFORDABLE WEBDESIGN!
http://mk3design.com
dnice [at] mk3design.com
-
Oct 25, 2005, 20:08 #21
- Join Date
- Oct 2005
- Posts
- 12
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
does this have anything to do with my problem?
PHP $dbh=mysql_connect ("localhost", "emcsbutv_game", "<PASSWORD HERE>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("emcsbutv_game");
-
Oct 25, 2005, 22:46 #22
- Join Date
- Oct 2005
- Location
- Sydney, Australia
- Posts
- 95
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Get rid of the word 'PHP' at the beginning. (Unless there is a <? infront of it which you didnt copy/paste.
-
Oct 26, 2005, 21:40 #23
- Join Date
- Oct 2005
- Posts
- 12
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
sorry I didn't explain that better here is a screen of the cause of the problem I think. You will notice that the PERL database connects, but not the PHP . . .
-
Oct 27, 2005, 04:09 #24
- Join Date
- Oct 2005
- Location
- Sydney, Australia
- Posts
- 95
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Nothing wrong with that. Just make sure you replace <PASSWORD HERE> with your password when you put it in your code.
-
Oct 27, 2005, 05:45 #25
- Join Date
- Jun 2004
- Location
- dublin, Ireland
- Posts
- 77
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
they're just examples of code you would use to connect.
If you're not seeing that error message your problem is likely elsewhere.
do you get a result from
PHP Code:select user,pass from players where user='myusername' and pass='mypassword'
edit:
it camestraight from the zip like this, all I changed was user="$user" because I didnt want people to login with email addresses.
i.e. is the name you type ( when logging in ) being stored in a field other than user?
Bookmarks