Jump to content

Recommended Posts

Hi Guys,

 

i cannot figure what has happened here! it was working earlier, but when the login button is clicked my script exits after the isset($_POST['']) is grabbed, the logic looks and worked fine earlier so i commented out a lot of it to see what the error was, can anyone see anything obvious at all!

 

<?php
//ob_start();
//session_start();

// INCLUDES
include("inc/inc-head.php");
include("inc/inc-functions.php");
include("inc/inc-db-connection.php");

// PRINT THE LOGIN PAGE
print("<form action=\"index.php\" method=\"POST\" />\n");

print("<table width=\"400\" cellpadding=\"5\" cellspacing=\"1\" class=\"tbl-border\" />\n");
print("<tr>");
print("<td colspan=\"2\" align=\"center\"><img src=\"img/img-cookie-head.jpg\" alt=\"Cookie Monster Pro v1.0\"></td>\n");
print("</tr>\n"); 
print("<tr>\n");
print("<td colspan=\"2\" align=\"left\" class=\"tbl-head\"><b>Login.</b></td>\n");
print("</tr>\n");
print("<tr class=\"tbl-pixels\">\n");
print("<td align=\"left\"><img src=\"img/img-pixel.gif\" width=\"1\" height=\"1\"></td><td align=\"left\"><img src=\"img/img-pixel.gif\" width=\"1\" height=\"1\"></td>\n");
print("</tr>\n");

// DO THE LOGIN VALIDATION
if (isset($_POST['submit-login']))
{

// INITAILSE ERRORS ARRAY
$errors = array();

  // THE POST VARS
  $userName = trim($_POST['txt_username']);
  $passWord = trim($_POST['txt_password']); 
  
  // MD5 THE PASSWORD FOP CHECKING
  $encPass = md5($passWord);

   // VALIDATE FIELDS
   if (empty($userName))
   {
    $errors[] = "You never entered your username.";
   }
   
   if (empty($passWord))
   {
    $errors[] = "You never entered your password.";
   }
   
    // CHECK TO SEE IF THE USERNAME/PASSWORD ARE IN THE DATABASE
    $qP = "SELECT `ADMIN_USERNAME`,`ADMIN_PASSWORD` FROM `cmp_admins` WHERE `ADMIN_USERNAME`='$userName' AND `ADMIN_PASSWORD`='$encPass' LIMIT 1";
    $rP = mysql_query($qP) or die (mysql_error());
    $aP = mysql_fetch_array($rP) or die (mysql_error());
    
      // RESULTS
      $numResults = mysql_num_rows($rP);
     
       // ERROR OUT IF THERE ARE NO RESULTS BACK
       if ($numResults < 1)
       {
        $errors[] = "Those login details don't appear to be in the database.";
       }
       
         // COUNT HOW MANY ERRORS THE ARRAY CONTAINS
         if (count($errors) > 0)
         {
           // PRINT HIDDEN <TR>
           print("<tr>\n");
           print("<td colspan=\"2\" align=\"left\">\n");
    
           print("<ol class=\"bullets\">");
        
           foreach($errors as $error)
           {
            print("<li><img src=\"img/img-bullet.gif\"> <b>$error</b>"); 
           } 
                           
           print("</ol>");  
      
           // END <TR>
           print("</tr>\n");
           print("</td>\n");
           
         } else {
           
           // NO ERRORS LOGIN SUCCESSFULLY AND SET SESSIONS
           //$_SESSION['SESSIONADMINID'] = $aP['ADMIN_ID'];
           //$_SESSION['SESSIONADMINUN'] = $aP['ADMIN_USERNAME'];
           //$_SESSION['SESSIONADLOGIN'] = "Yes"; 
           
           //header("Location: main.php"); 
           //ob_clean();  
     }
     
}

print("<tr class=\"tbl-alternate\">\n");
print("<td align=\"left\">Username:</td><td class=\"class=\"font_for_forms\" align=\"left\"><input type=\"text\" size=\"40\" name=\"txt_username\" /></td>\n");
print("</tr>\n");
print("<tr>\n");
print("<td align=\"left\">Password:</td><td class=\"class=\"font_for_forms\" align=\"left\"><input type=\"password\" size=\"40\" name=\"txt_password\" /></td>\n");
print("</tr>\n"); 
print("<tr class=\"tbl-alternate\">\n");
print("<td colspan=\"2\" align=\"right\" class=\"tbl-button\"><input type=\"submit\" name=\"submit-login\" value=\"Login\"></td>");
print("</tr>\n");
print("</table></form>");

?>

<?php
include("inc/inc-foot.php");
?>

 

Thanks guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/135929-login-script-exiting/
Share on other sites

Add this Code

 

error_reporting(E_ALL);

 

After The Very First <php

 

And tell us what errors come up

 

Just a side note here. error_reporting will not do much if display_errors is off.

 

error_reporting(E_ALL);
ini_set("display_errors", 1);

 

I generally always use those in combination. I looked at the code and it looks alright, but I will keep looking to see if I see anything.

 

Generally when that happens I tend to do echos such as "echo 'HERE1'; at parts of the script to see where it stops working and just iterate the number after here. That will take you to the source and help you figure out what if/loop etc is causing the problem.

Link to comment
https://forums.phpfreaks.com/topic/135929-login-script-exiting/#findComment-708609
Share on other sites

Hi Mate,

 

its a weird one! i checked and the isset($_POST['']) is catching data ok on troubleshooting i have found this:

 

    // CHECK TO SEE IF THE USERNAME/PASSWORD ARE IN THE DATABASE
    $qP = "SELECT `ADMIN_USERNAME`,`ADMIN_PASSWORD` FROM `cmp_admins` WHERE `ADMIN_USERNAME`='$userName' AND `ADMIN_PASSWORD`='$encPass' LIMIT 1";
    $rP = mysql_query($qP) or die (mysql_error());
    $aP = mysql_fetch_array($rP) or die (mysql_error());
    print $qP;

 

i can't echo out the above query if the credentials are typed in wrong (it exits the script) but if they are typed correctly then the script echos out the query!

 

im stumped lol

 

so the error lies here:

 

// DO THE LOGIN VALIDATION
if (isset($_POST['submit-login']))
{

// INITAILSE ERRORS ARRAY
$errors = array();

  // THE POST VARS
  $userName = trim($_POST['txt_username']);
  $passWord = trim($_POST['txt_password']); 
  
  // MD5 THE PASSWORD FOP CHECKING
  $encPass = md5($passWord);

   // VALIDATE FIELDS
   if (empty($userName))
   {
    $errors[] = "You never entered your username.";
   }
   
   if (empty($passWord))
   {
    $errors[] = "You never entered your password.";
   }

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/135929-login-script-exiting/#findComment-708641
Share on other sites

    // CHECK TO SEE IF THE USERNAME/PASSWORD ARE IN THE DATABASE
    $qP = "SELECT `ADMIN_USERNAME`,`ADMIN_PASSWORD` FROM `cmp_admins` WHERE `ADMIN_USERNAME`='$userName' AND `ADMIN_PASSWORD`='$encPass' LIMIT 1";
    print $qP . "<br />";
    $rP = mysql_query($qP) or die (mysql_error());
    print $qP . "<br />" . mysql_error();
    $aP = mysql_fetch_array($rP) or die (mysql_error());

 

Chances are the die is hitting, see what the $qP displays, if you see it twice it dies at the fetch_array. See how the sql statement is formatted and see if you cannot see the error message.

Link to comment
https://forums.phpfreaks.com/topic/135929-login-script-exiting/#findComment-708644
Share on other sites

It just means you need to adjust your logic:

 

if (mysql_num_rows($rP) > 0) {
    $aP = mysql_fetch_array($rP);
}

 

That way if there are rows to return it does, else it does not throw an error and die. Really you should not have a die on the fetch array portion, just the query portion.

 

The above logic is not needed unless you want it, just remove the die and it will return an empty array I believe or false.

Link to comment
https://forums.phpfreaks.com/topic/135929-login-script-exiting/#findComment-708660
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.