PHP error msg

Experts,

Check out http://www.cuedspeech.org/test/contact-cued-speech.php.

Why am I getting this error -       
Notice: Undefined variable: alert in C:\Sites\Premium9\cuedspeech\webroot\test\contact-cued-speech.php on line 151

Heres the code I'm using and its producing the error message above:
<td><?php echo $alert; ?></td>

Why do you think that is!?  

Rob
RobWellsMcAsked:
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.

kumaranmcaCommented:
Hi Rob,

Variable name $alert not defined before... so you get the notice error...Check your previous line code.


0
sgvillCommented:
its telling you that your variable $alert  has not been defined.    define it and initialize it and it should work.
0
RobWellsMcAuthor Commented:
I think I definied it in the PHP area above my webpage before the HTML code, here it is:

$alert = $_POST['alert'];

Any better ideas or variable declarations?
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

sgvillCommented:
Are you sure its hitting that line of code?  is it in an if block, for instance, that is not getting triggered?
0
RobWellsMcAuthor Commented:
still not sure what you mean.  Can you cite an example?
0
sgvillCommented:
if you have something like this:

if (some condition)  {
   ....
   $alert = $_POST['alert'];
   ......
}

then, if the condition is false, $alert never gets initialized.  If this is the case,  *before* the if statement, initialize alert with something like the following:

$alert = "";
0
Dave BaldwinFixer of ProblemsCommented:
I believe that if $_POST['alert'] isn't defined, then $alert wont' be either.  I normally use this code to make sure it's defined to something.

if (isset($_POST['alert'])) $alert = $_POST['alert']; else $alert = '0';

Open in new window

0
RobWellsMcAuthor Commented:
Still no luck.  Will go at it tomorrow.  Thanks guys!
0
hieloCommented:
>>I think I definied it in the PHP area above my webpage before the HTML code, here it is:
>>$alert = $_POST['alert'];

But in your form there is no form field with name='alert', so $_POST['alert'] will always be undefined and so will $alert.
If you want the error to go away you can use:
$alert = isset($_POST['alert']) && !empty($_POST['alert']) ? $_POST['alert'] : '';

BUT that still doesn't change/fix the "main" problem - namely, that $_POST['alert'] will always be undefined whenever you submit the form because there is no such element in your form.
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
RobWellsMcAuthor Commented:
Perfect, that did it because this time I had the code in between the <head></head> tags instead of the PHP area before the <html> code so that it could be part of the HTML code  *before the form action & submittal*.  
I was having this problem on this server my client uses. I *never* have this problem on my personal server - Dreamhost.  Love Dreamhost!

Guys, I'm sure some of your suggestions worked as well...

Thanks again!

Rob
0
RobWellsMcAuthor Commented:
Perfect, got it working, thanks guys!!!
0
RobWellsMcAuthor Commented:
Here's what I put in that worked:

<head>
<?php
$notice = isset($_POST['notice']) && !empty($_POST['notice']) ? $_POST['notice'] : '';
?>
</head>
0
RobWellsMcAuthor Commented:
Sorry, I mean, in this one I was working on, same thing!

<head>
<?php
$alert = isset($_POST['alert']) && !empty($_POST['alert']) ? $_POST['alert'] : '';
?>

</head>
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.