Page 1 of 1

WAMP Login Page - Processing Page Blank

Posted: Wed Aug 05, 2009 4:17 pm
by WorldIsYours
I am designing a PHP-based game. I run Apache 2.2, MySQL 5.1.37, and PHP 5.3.0 VC9 on Windows XP Pro SP3.

I have a login page which passes the username and password of the log-in-er to the processing page which SHOULD check the password against the SQL database, and print text saying that it did so.

Long story short, it doesn't. In fact, it gives me a blank page.

Here's the code:

The login page:

Code: Select all

<form action="login.php" method="post" target="_self">
        USERNAME:<INPUT type="text" name="user"><br>
        PASSWORD:<INPUT type="password" name="pass"><br>
        <input type="submit" value="Login">
    </form>
The processing page(login.php):

Code: Select all

<?php
        
        $user = $_POST['user'];
        $pass = $_POST['pass'];
        
        $dbh = mysql_connect(localhost:mysql,web,secret);
        mysql_select_db(worldisyours,$dbh);
        
        $sql = "SELECT * FROM users WHERE username = $user";
        mysql_escape_string($sql);
        $result = mysql_query($sql,$dbh);
        
        $array = mysql_fetch_array($result,MYSQL_ASSOC);
        $passcomp = $array['password'];
        
        if($passcomp==$pass){
            $_SESSION['user'] = $user;
            $_SESSION['pass'] = $pass;
            $_SESSION['email'] = $array['email'];
            print "Successful login.  Welcome, $_SESSION['user']!  Your last login: $array['last'].";
            $date = date(D j M at i:g:A);
            $sql = "UPDATE users SET last=$date WHERE username = $_SESSION['user']";
            mysql_escape_string($sql);
            $result = mysql_query($sql,$dbh);
        }
        else
        {
            print "<a href='index.php'>Incorrect password.</a>";
        }
?>
My database runs on localhost, and contains the following relevant stuffs:

Schema: worldisyours
Table: users
Columns: id(INT(10))(PRIMARY KEY), username(VARCHAR(45)), password(VARCHAR(45)), email(VARCHAR(100)), last(VARCHAR(45))

Id being primary key, username and password being obvious, and last being the last login time.

I have one row in there which I test using.
I have already run numerous web searches on syntax and read up on everything I am using including PRINT, SQL Queries, the various sql functions I use, session variables, and it appears to me that I am implementing everything correctly. Obviously I'm not. Suggestions?

Re: WAMP Login Page - Processing Page Blank

Posted: Thu Aug 06, 2009 9:02 am
by jackpf
Try putting curly braces around arrays when echoing them within double quotes.

There's also an error on line 6.

TURN ON ERROR REPORTING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Re: WAMP Login Page - Processing Page Blank

Posted: Thu Aug 06, 2009 9:06 am
by superdezign
jackpf wrote:There's also an error on line 6.
And 7.

mysql_connect() and mysql_select_db() take strings as parameters. Strings have quotation marks around them.

Re: WAMP Login Page - Processing Page Blank

Posted: Thu Aug 06, 2009 9:14 am
by jackpf
I thought they were constants.

Line 6 has an error cause of the random colon. If they're not constants, then yes, so does line 7.


But the moral of the story: TURN ON ERROR REPORTING!

Re: WAMP Login Page - Processing Page Blank

Posted: Thu Aug 06, 2009 9:22 am
by superdezign
jackpf wrote:Line 6 has an error cause of the random colon. If they're not constants, then yes, so does line 7.
If this is the complete page, then the constants were never declared.

Re: WAMP Login Page - Processing Page Blank

Posted: Thu Aug 06, 2009 9:29 am
by jackpf
Aha - but you cannot be sure that this is the whole script -_^


Anyway, the only person who can is the OP. And...he/she seems to have gone. :|

Re: WAMP Login Page - Processing Page Blank

Posted: Thu Aug 06, 2009 9:34 am
by superdezign
PHPDN is too active for them. Didn't expect such a quick response, I assume.
DevNet ftw.

Re: WAMP Login Page - Processing Page Blank

Posted: Thu Aug 06, 2009 9:39 am
by jackpf
Lol yeah. No life and nothing better to do than respond to people's coding issues FTW as well!

Re: WAMP Login Page - Processing Page Blank

Posted: Wed Aug 12, 2009 4:18 pm
by WorldIsYours
Hey guys,
Thanks for all the tips. My internet has been down the past four or five days, and you're right, I did not expect such a quick response. That is the whole script, by the way.

Now looks like this:

Code: Select all

<?php
        
        $user = $_POST['user'];
        $pass = $_POST['pass'];
        
        $dbh = mysql_connect('localhost:3306','web','secret');
        mysql_select_db('worldisyours',$dbh);
        
        $sql = "SELECT * FROM users WHERE username = $user";
        mysql_escape_string($sql);
        $result = mysql_query($sql,$dbh);
        
        $array = mysql_fetch_array($result,MYSQL_ASSOC);
        $passcomp = $array['password'];
        
        if($passcomp==$pass){
            $_SESSION['user'] = $user;
            $_SESSION['pass'] = $pass;
            $_SESSION['email'] = $array['email'];
            print("Successful login.  Welcome, {$_SESSION['user']}!  Your last login: {$array['last']}.");
            $date = date("D j M at i:g:A");
            $sql = "UPDATE users SET last = {$date} WHERE username = {$_SESSION['user']}";
            mysql_escape_string($sql);
            $result = mysql_query($sql,$dbh);
        }
        else
        {
            print("<a href='index.php'>Incorrect password.</a>");
        }
?>
I have done everything you told me to, and am now getting a new error:

"Fatal error: Call to undefined function mysql_connect() in C:\WEB\JEFF\login.php on line 13"
(Line 6 in the above script.)

I have done the following:

Defined my extension directory in php.ini and enable php_mysql.dll.
Copied libmySQL.dll to system32, windows, and php root.
Restarted apache.

Did I miss a step? If so, what is it?
(My server can be moody though. I was having POST trouble before and changed something in the file that was using it, and changed it back and it now works fine.)

UPDATE: phpinfo() doesn't list any additional modules.

Re: WAMP Login Page - Processing Page Blank

Posted: Wed Aug 12, 2009 5:02 pm
by WorldIsYours
FIXED IT!

My php.ini file: located in C:\Windows

My PHPIniDir directive in the httpd.conf file: C:\Program Files\PHP

Moved php.ini to PHP folder.

Thanks for everything, guys. I'll be devving this game for a while... see you around. Probably soon (LOL).

Re: WAMP Login Page - Processing Page Blank

Posted: Fri Aug 14, 2009 10:00 am
by jackpf
Nice one.