WAMP Login Page - Processing Page Blank

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

Post Reply
WorldIsYours
Forum Newbie
Posts: 3
Joined: Wed Aug 05, 2009 4:03 pm

WAMP Login Page - Processing Page Blank

Post 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?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: WAMP Login Page - Processing Page Blank

Post 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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: WAMP Login Page - Processing Page Blank

Post 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.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: WAMP Login Page - Processing Page Blank

Post 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!
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: WAMP Login Page - Processing Page Blank

Post 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.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: WAMP Login Page - Processing Page Blank

Post 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. :|
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: WAMP Login Page - Processing Page Blank

Post by superdezign »

PHPDN is too active for them. Didn't expect such a quick response, I assume.
DevNet ftw.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: WAMP Login Page - Processing Page Blank

Post by jackpf »

Lol yeah. No life and nothing better to do than respond to people's coding issues FTW as well!
WorldIsYours
Forum Newbie
Posts: 3
Joined: Wed Aug 05, 2009 4:03 pm

Re: WAMP Login Page - Processing Page Blank

Post 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.
WorldIsYours
Forum Newbie
Posts: 3
Joined: Wed Aug 05, 2009 4:03 pm

Re: WAMP Login Page - Processing Page Blank

Post 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).
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: WAMP Login Page - Processing Page Blank

Post by jackpf »

Nice one.
Post Reply