SitePoint Sponsor

User Tag List

Results 1 to 25 of 25

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation 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;

    if I remove that code the stats for the game no longer work, and if I leave it, I can't see anything, except "Invalid login", which is BS, because I have allready logged in, on the login.php page

    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.

  2. #2
    Sell crazy someplace else markl999's Avatar
    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.');


  3. #3
    SitePoint Member
    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"?

  4. #4
    Sell crazy someplace else markl999's Avatar
    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.

  5. #5
    SitePoint Member
    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]");
    ?>
    thats the whole coding right there, except for the tables coding which includes all of the stats which are BLANK right now.

  6. #6
    Sell crazy someplace else markl999's Avatar
    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

  7. #7
    SitePoint Member
    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.

  8. #8
    Sell crazy someplace else markl999's Avatar
    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;

    replace it with:
    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.');

    It's the same as your code just with some debugging in it.

  9. #9
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DEBUG: $query
    Invalid Login.

  10. #10
    Sell crazy someplace else markl999's Avatar
    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 />';

  11. #11
    SitePoint Member
    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.

  12. #12
    SitePoint Member
    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.

  13. #13
    Sell crazy someplace else markl999's Avatar
    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?

  14. #14
    SitePoint Member
    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?

  15. #15
    Sell crazy someplace else markl999's Avatar
    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);

  16. #16
    SitePoint Member
    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.

  17. #17
    Sell crazy someplace else markl999's Avatar
    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.

  18. #18
    SitePoint Member
    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 . . .

  19. #19
    SitePoint Enthusiast Anne Thrax's Avatar
    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.

  20. #20
    SitePoint Enthusiast D-Nice's Avatar
    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

  21. #21
    SitePoint Member
    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");

  22. #22
    SitePoint Enthusiast Anne Thrax's Avatar
    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.

  23. #23
    SitePoint Member
    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 . . .


  24. #24
    SitePoint Enthusiast Anne Thrax's Avatar
    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.

  25. #25
    SitePoint Enthusiast
    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' 
    or does it show 0 results?

    edit:
    it camestraight from the zip like this, all I changed was user="$user" because I didnt want people to login with email addresses.
    can you show the schema from the database? is the field in the database called emailaddress or something simliar?

    i.e. is the name you type ( when logging in ) being stored in a field other than user?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •