Jump to content

Error with a log entry


Phaelon

Recommended Posts

Hey all,

 

I am getting an error with PHP where my page halts, but there is nothing in the error log to indicate why.

 

The error is specifically with the subroutine if ($row['email'] == '') {, everything else works fine. Does anyone have any ideas?

 

 

<?php
    session_start();
    if (isset($_POST["e-mail"])) {
        $link = mysql_connect('localhost', 'testuser', 'testpw') OR die(mysql_error());
        mysql_select_db('testdb', $link);
        $query = "SELECT * FROM customers WHERE email = '".mysql_real_escape_string($_POST["e-mail"])."'";
        $result = mysql_query($query);
        while ($row = mysql_fetch_assoc($result)) {
            if ($row['email'] == '') {
                mysql_close($link);
                echo 'notregistered';
                exit;
            }
            if ($row['password'] != $_POST["password"]) {
                mysql_close($link);
                include 'wrongpassword';
                exit;
            }
            if ($row['password'] == $_POST["password"]) {
                mysql_close($link);
                $_SESSION['login']['customernumber'] = $row['number'];
                header('Location: http://test.com/account/');
                exit;
            }
        }
    } else {
        include 'login';
    }
?>
Link to comment
https://forums.phpfreaks.com/topic/288189-error-with-a-log-entry/
Share on other sites

"I am getting an error with PHP."

 

How do you know it's an error?

 

A pervasive mistake I see is this:

while ($row = mysql_fetch_assoc($result)) {

 

Technically, you are testing for $row containing a non-false value, but you are not doing anything should the expression for while() be false.

 

mysql_fetch_assoc could return false - and it eventually will - but return false immediately.

 

Sketch your flowchart and determine where program control flows when while() is false.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.