isset undefined variable


Posted on 16th Feb 2014 07:03 pm by admin

Hi all,

Hope someone can point out the obvious. I've a log in script, if you dont enter a username or pw, you get a red asterix show by the field and a pop up.

Did you know?Explore Trending and Topic pages for more stories like this.
If you enter an email but not the pw, it says Undefined variable: email_error .

This is the code:

// Validate the email address.
if (!empty($_POST['email'])) {
$e = escape_data($_POST['email']);
} else {
echo '<script type="text/javascript">alert("You forgot to enter your email address!");</script>';
#echo '<p class="error">You forgot to enter your email address!</p>';
$e = FALSE;
$email_error = '<span class="required"><img src="images/star.gif" /></span>';
}

// Validate the password.
if (!empty($_POST['pass'])) {
$p = escape_data($_POST['pass']);
} else {
$p = FALSE;
echo '<script type="text/javascript">alert("You forgot to enter your password!");</script>';
$pw_error = '<span class="required"><img src="images/star.gif" /></span>';
#echo '<p class="error">You forgot to enter your password!</p>';
}

My form looks like:

<form action="login.php" method="post">
<table border="0" width="310">
<tr>
<td><img src="images/email_address.gif" /></td>
<td><div class="myBoxLh"></div><input type="text" name="email" style="width:150px;" maxlength="90" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /><div class="myBoxRh"></div><?php if (isset($_POST['submitted'])) { echo $email_error; }?></td>
</tr>
<tr>
<td><img src="images/password.gif" /></td>
<td><div class="myBoxLh"></div><input type="password" name="pass" style="width:150px;" maxlength="20" /><div class="myBoxRh"></div><?php if (isset($_POST['submitted'])) { echo $pw_error; }?></td>
</tr>
<tr>
<td colspan="2"><div align="left"><?php if (isset($_POST['submitted'])) { echo $error_message; }?></div><div align="right"><input type="image" src="images/submit.jpg" name="submit" value="Login" class="submit_small" /></div>
<input type="hidden" name="submitted" value="TRUE" /></td>
</tr>
</table>
</form>


How can I stop this error as I thought I'd coded the correct way?

Thanks in advance
No comments posted yet

Your Answer:

Login to answer
71 Like 15 Dislike
Previous forums Next forums
Other forums

Object Interfaces
EDIT: Never mind, I just updated to php 5.

Hey all,

I'm currently experimenting with p

Click counter to ignore traffic from search bots
I have a click counter on my site that...well, counts the number of clicks a link gets on the frontp

Help on code output
My CODE:

Code: [Select] echo "<phone>".$line["phone"].&qu

How can I get my program to read a larger array ??
Hi:

I have this program that reads from an array to do calculations. The array are just t

How would I convert this into code using an if statement?
ES equals exam score m equals $mean s equals $total. I already coded my mean and total so I'm not g

array_combine() error
getting an "Warning: array_combine() [function.array-combine]: Both parameters should have an e

GET vs SUBMIT Button to show sections on one index.php page?
Just curious if one of these ways is better (i.e. more efficient) than the other.

I have a

Lack of simpleXML Documentation
What is up with this.

Look at: http://www.php.net/manual/en/function.simplexml-load-file.php<

How do i do multi uploads?.
Hey i would like to do this : http://hosting.mrkrabz.net/

I've got the base down you can uplo

Help: calling function
Hi,
Is it possible to call a php function on page close?
If yes, could you explain how and whe

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash