Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Error displaying the error page: Application Instantiation Error

What causes the above. The executing php program grinds about 2 minutes, then  shows this.

Program here:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
include "db_connect.php";
//echo "uid = " . $_POST['uid'] . "<br>";
//echo "pwd = " . $_POST['pwd'] . "<br>";
$qry = "SELECT * from admins where email = '" . $_POST['uid'] . "' and pwd = '" . $_POST['pwd'] . "'";
$res = mysqli_query($link, $qry);
$nr = mysqli_num_rows($res);
if ($nr == 0) {
	// invalid login
	$_SESSION['admin_login'] = "";
	header("Location: admin_login.php?bad=Y");
} else {
	$_SESSION['admin_login'] = $_POST['pwd'];
	header("Location: admin_login.php");
}
exit;	
?>

Open in new window


When I uncommented the echos, it instantly gave an error message on one of the headers (of course expected because headers already sent).

db_connect.php is used in all the other programs that need db access; it works fine. I could show it but I'll need to edit out the real password, etc.
chk_login.php
Avatar of themrrobert
themrrobert
Flag of United States of America image

You are using Joomla, correct?

That error is typically caused from incorrect user credentials, or a failure to connect to the database.

Since you said it grinds for about 2 minutes, it sounds like it's attempting to connect to the database, but then timing out.

Are the other programs on the same server as this, or are they on a separate server?
Avatar of Dave Baldwin
There is nothing in that code to cause an error except for missing $_POST data.  You did not show the error message.
Avatar of Richard Korts

ASKER

themrrobert,

I am NOT using Joomla; this is hand coded php. Everything is hand coded php.

All the other programs work (on THIS server).

Thanks
Error message?  You'e not giving us anything to work with.
Are you sure that's the entire error? Is there anything after Application Instantiation Error?

It still sounds like the database is timing out, or possibly taking too long to return a value.

Also, you should probably be assigning the $_POST['uid'] To your session variable and NOT the password.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dave,

The subject of the post is EXACTLY what was displayed in the browser.
Yes, the subject line leads us to believe that this is a Joomla problem because that is a common message when Joomla has incorrect database credentials.  But it is an incomplete message; more information is usually displayed by Joomla, as this article shows.  Anyway, once we see the var_dump() output we will know where to look next.
Fascinating problem.

I performed the following steps:

(1) Took Ray's code as is copied it and saved it calling it rayp.php. I noticed that there was no closing ?>. Knowing Ray, I figured that was on purpose, but I put one in anyway. I modified the "calling" program (called admin_menu.php, see attached) to make the form action rayp.php. I ran it. Exactly the same result.

(2) I figured I blew it by putting in the closing ?>. So I removed it and ran it again. Exactly the same result.

(3) I thought that there was supposed to be some sort of ob_close (to see the contents of the output buffer), wasn't sure what that was supposed to be so I used ob_end_flush();. Ran it again, exactly the same result.

(4) I created a login called "eetest@gmail.com" with password "1234abcd". I turned the echos I had back on & added one to show the query being run against the database. Result attached (output.txt). Maybe there is something there that sheds light?

I don't know what the E-E Code Snippet is, so I used attachments instead..

Also attached is rayp.php, exactly as it is when it produced output.txt.

Try it at www.rkassoc.org/Lakos/admin_menu.php.

It looks to me like it almost works (except for the header) with the echos turned on. I'm clueless as to why, but you guys are the experts.

Thanks
output.txt
rayp.php
admin_menu.php
The subject of the post is EXACTLY what was displayed in the browser.
The code you posted can't generate that message... so it must be from something you haven't shown us.
The code I posted was intended to be run as-is.  Here are a couple of points that you may want to consider.

The close-PHP ?> tag is almost never needed; most modern coding standards advise us not to use it, and it often causes  bizarre and difficult-to-find errors, so I left it out on purpose.  To learn more about this, and other ideas and practices that should NOT be part of your PHP work, have a look at this article.
https://www.experts-exchange.com/articles/12293/AntiPHPatterns-and-AntiPHPractices.html

The ob_start() statement does not need any other statement to  have the desired effect, which is to allow browser output to be trapped in the PHP buffer.  It's almost always a good idea, from a performance viewpoint, to use it.  PHP knows when the script has ended, and it will flush the output to the browser without any prodding from us.  Omitting it causes a logic error because of the browser output.

The E-E code snippet is activated by clicking the word "CODE" in the editor bar at the top of the "WRITE COMMENT" box (This is the bar that starts B I U ...).  It will produce a pair of bbcode tags and will put the cursor in the right place for a "paste" operation.

Let's try it once again, please.  I would really like to see the output we asked for, using the script as it was written and posted.

<?php

// START THE OUTPUT BUFFER
ob_start();

error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();

// SHOW THE REQUEST VARS
var_dump($_POST);
var_dump($_SESSION);

include "db_connect.php";
//echo "uid = " . $_POST['uid'] . "<br>";
//echo "pwd = " . $_POST['pwd'] . "<br>";
$qry = "SELECT * from admins where email = '" . $_POST['uid'] . "' and pwd = '" . $_POST['pwd'] . "'";

// SHOW THE DB LINK AND THE QUERY
var_dump($link);
var_dump($qry);

$res = mysqli_query($link, $qry);
$nr = mysqli_num_rows($res);

// SHOW THE NUMBER OF ROWS FROM THE QUERY
var_dump($nr);

if ($nr == 0) {
    // invalid login
    $_SESSION['admin_login'] = "";
    header("Location: admin_login.php?bad=Y");
} else {
    $_SESSION['admin_login'] = $_POST['pwd'];
    header("Location: admin_login.php");
}
exit;

Open in new window

As I said before, it produces the SAME result as originally posted.

See attached.
Image1.jpg
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Interesting.  We get the same message when we visit http://rkassoc.org/ and it takes a long time for the message to appear.  It looks like there is some confusion about the redirection of the scripts.

When I visit http://rkassoc.org/Lakos/ I get a collection of drop-down select controls.

When I visit http://rkassoc.org/Lakos/admin_login.php (same address as the header("Location") script) I get the same behavior with the error message.

When I visit http://rkassoc.org/Lakos/gooseball.php (different address as the header("Location") script) I get the same behavior with the error message.

I also see a GET request for http://rkassoc.org/favicon.ico that ends in 404 (Not Found)

Who is your hosting company?  It looks like the server may not have a path to admin_login.php.  Other tests to random URLs inside http://rkassoc.org/ ended with identical error messages.  This suggests to me that the message you're seeing comes from the generic 404 error handler.
Ray,

My hosting company is ChiHost.
I found the issue.

I stupidly used admin_login.php in the headers in the original program & in Ray's version. There is no admin_login.php in that driectory on that server.

It's supposed to be admin_menu.php.

I changed it to that & it works perfectly.

Richard
This suggests to me that the message you're seeing comes from the generic 404 error handler.
Yup.  

I love ChiHost - very dependable!
Thanks for your efforts; I learned a lot about output buffering, etc.

As I'm sure you know, & I thought to be in this case, it's VERY often something obvious that we just can't see.

I have done similar code 100's of times. Helps if you refer to the name the php file correctly.