When using this PHP code, I get the following error: Notice: Undefined index: error in C:\Apache24\htdocs\index.php on line 42
<?php
if ($error == 'true' && isset($error)) { //This is line 42
echo "<div><p>There was an error</p>
<p><img src=\"errorclose.png\"></p></div>";
};
?>
Funny enough, when $error is equal to true, however, the code works perfectly.
Why is the error occurring? Is there a syntax error?
Escape the quotes and I think you should do fine.
<?php
if ($error == 'true') {
echo "<div><p>There was an error</p>
<p><img src=\"errorclose.png\"></p></div>";
};
?>
Try this one:
if ($error == 'true') {
echo "<div><p>There was an error</p>
<p><img src="errorclose.png"></p></div>";
};
Your $error
is not set, use isset()
for check variable is set or not, something like
if (isset($error) && $error == 'true') {
echo "<div><p>There was an error</p>
<p><img src='errorclose.png'></p></div>";
};
Also There is quote problem into img tag, use '
instead of "
<img src='errorclose.png'>
//-------^
change your code to:
if ($error == true && !empty($error)) {
echo "<div><p>There was an error</p> <p><img src='errorclose.png'></p></div>";
}
if((isset($error)) && ($error==true))
{
echo '
'."There was an error".'
';}