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
Richard KortsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

themrrobertCommented:
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?
0
Dave BaldwinFixer of ProblemsCommented:
There is nothing in that code to cause an error except for missing $_POST data.  You did not show the error message.
0
Richard KortsAuthor Commented:
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
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Dave BaldwinFixer of ProblemsCommented:
Error message?  You'e not giving us anything to work with.
0
themrrobertCommented:
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.
0
Ray PaseurCommented:
If you want to get a head-start by using some code that is already tested, you might find this article helpful.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html

If you want to try to debug this code, please try it this way and show us all of the exact output (copy/paste into the E-E Code Snippet).
<?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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard KortsAuthor Commented:
Dave,

The subject of the post is EXACTLY what was displayed in the browser.
0
Ray PaseurCommented:
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.
0
Richard KortsAuthor Commented:
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
0
Dave BaldwinFixer of ProblemsCommented:
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.
0
Ray PaseurCommented:
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.
http://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

0
Richard KortsAuthor Commented:
As I said before, it produces the SAME result as originally posted.

See attached.
Image1.jpg
0
Dave BaldwinFixer of ProblemsCommented:
After reading thru all these posts, I'm pretty sure that the error is in 'admin_login.php' and not in the code you have posted.
0
Ray PaseurCommented:
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.
0
Richard KortsAuthor Commented:
Ray,

My hosting company is ChiHost.
0
Richard KortsAuthor Commented:
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
0
Ray PaseurCommented:
This suggests to me that the message you're seeing comes from the generic 404 error handler.
Yup.  

I love ChiHost - very dependable!
0
Richard KortsAuthor Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.