Hi I am a still a beginner in programming and I wanted to know if you guys could help me on what is cause the error to pop out. If you guys could track what is wrong on my codes could you also try to correct it? Thanks in advanced.
You will get that undefined index error when the POST key or any array key is not present. It’s a good idea to wrap any code dealing with these keys in a isset() statement so it is only used when it IS SET.
I tried the code above and it did work, just one problem for me now after this : It leads me to nothing. I made a HTML before which was the login page for my PHP but when i login with the right info it just leads me to a white space. Any ideas on why this happened?
A white screen usually means a fatal error occurred. This probably happens while making the query. If you have access to the errors logs it would tell you what is causing this error. Did your host upgrade to a new version of php? If you can post your full login code maybe someone can spot the issue.
Yes I didn’t “fix” any code within what was posted. I only was pointing out that the code should not be run if POST isn’t present as you I assume you are querying the DB for username and password for the login script. Wrap it within an IF condition. See if you can isolate the problem area by commenting parts out. Here’s adjusted code.
$username = $_POST['username'];
$password = $_POST['password'];
if ($username == "j12345" && $password == "spcm")
echo '<img src="right.jpg">';
echo '<img src="wrong.jpg">';
//The rest of your login code
You can also comment out sections of your code
to isolate the blank screen error like I've done
with this text. More than likely when viewing the
source of the blank screan you will see a 1.
Not much help, I know. As you seem to be just
using these images to test POST then isolate the
problem then ask for help with the problem code or
post the whole page you are having trouble with.
Whenever I have blank screens I use the following script to display the line number and stop the remaining page from displaying.
If the line number displays OK then I move the line to halfway down the page. If the page is blank then I move the line halfway up the previous lines. This procedure is repeated until the offending script with the error is located.
echo '<br />line: ' .__LINE__;die;
// moved either up or down depending whether or not line number shows.