KANJE Posted May 30, 2012 Share Posted May 30, 2012 Hello guys PLEASE HELP ME ON THI ISSUE <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel = "stylesheet" type = "text/css" href = "stylesheet.css"> <title>Saint Agustine University of Tanzania</title> <style type="text/css"> <!-- .error {color: #FF0000} --> </style> </head> <body> <table width="638" height="393" border="1" align="center"> <tr> <td height="83"><div align="center" class="style1"> <p>Saint Augustine University of Tanzania </p> <p>Examination Management System </p> </div></td> </tr> <tr> <td width="487" height="243"> <form name= "login" method="POST" action="insertLogin.php"> <table width="269" border="0" align="center"> <tr> <?php echo "<span class=\"error\">".$_GET['message']."</span>"; ?> </tr> <tr bordercolor="#E7F2F8"> <td width="82">User name</td> <td width="171"><label> <input name="username" type="text" /> </label></td> </tr> <tr bordercolor="#E7F2F8"> <td>password </td> <td><label> <input name="password" type="password"/> </label></td> </tr> <tr bordercolor="#E7F2F8"> <td> <div align="right"> <input type="submit" name="Submit2" value="Submit" /> </div></td><td><label> </label> <input type="reset" name="Submit22" value="Clear" /></td> </tr> </table> </form> </td> </tr> <tr> <td height="28" bgcolor="#FFCC00">©Copyright by Saint Augustine University of Tanzania </td> </tr> </table> </body> </html> THE RESULT OF IS Notice: Undefined index: message in C:\wamp\www\sautems\index.php on line 33 Link to comment https://forums.phpfreaks.com/topic/263376-undefined-index-message/ Share on other sites More sharing options...
smoseley Posted May 30, 2012 Share Posted May 30, 2012 Change <?php echo "<span class=\"error\">".$_GET['message']."</span>"; ?> To <?php if (isset($_GET['message'])) echo "<span class=\"error\">".$_GET['message']."</span>"; ?> Link to comment https://forums.phpfreaks.com/topic/263376-undefined-index-message/#findComment-1349764 Share on other sites More sharing options...
PravinS Posted May 30, 2012 Share Posted May 30, 2012 You can disable error reporting NOTICE in PHP.INI configuration file. Link to comment https://forums.phpfreaks.com/topic/263376-undefined-index-message/#findComment-1349766 Share on other sites More sharing options...
KANJE Posted May 30, 2012 Author Share Posted May 30, 2012 hello smoseley the result of your solution is 1 sorry pbs how to disable error reporting NOTICE in PHP.INI configuration file. Link to comment https://forums.phpfreaks.com/topic/263376-undefined-index-message/#findComment-1349772 Share on other sites More sharing options...
ManiacDan Posted May 30, 2012 Share Posted May 30, 2012 The solution to bad code is NEVER "turn off error reporting." Fix your code. Fix your code like this: <?php echo "<span class=\"error\">".(isset($_GET['message']) ? $_GET['message'] : '')."</span>"; ?> This snippet makes use of the ternary operator Link to comment https://forums.phpfreaks.com/topic/263376-undefined-index-message/#findComment-1349775 Share on other sites More sharing options...
KANJE Posted May 30, 2012 Author Share Posted May 30, 2012 thankx ManiacDan i fixed it Link to comment https://forums.phpfreaks.com/topic/263376-undefined-index-message/#findComment-1349779 Share on other sites More sharing options...
smoseley Posted May 31, 2012 Share Posted May 31, 2012 The solution to bad code is NEVER "turn off error reporting." Fix your code. Fix your code like this: <?php echo "<span class=\"error\">".(isset($_GET['message']) ? $_GET['message'] : '')."</span>"; ?> This snippet makes use of the ternary operator Actually, no... my solution is the correct one. Yours will echo the error span whether or not there is an error. Wrong place for a ternary. Link to comment https://forums.phpfreaks.com/topic/263376-undefined-index-message/#findComment-1349968 Share on other sites More sharing options...
smoseley Posted May 31, 2012 Share Posted May 31, 2012 You can disable error reporting NOTICE in PHP.INI configuration file. Not generally a good idea in a development environment. Turning off notices is the lazy way to "fix" this problem. Link to comment https://forums.phpfreaks.com/topic/263376-undefined-index-message/#findComment-1349969 Share on other sites More sharing options...
ManiacDan Posted May 31, 2012 Share Posted May 31, 2012 The solution to bad code is NEVER "turn off error reporting." Fix your code. Fix your code like this: <?php echo "<span class=\"error\">".(isset($_GET['message']) ? $_GET['message'] : '')."</span>"; ?> This snippet makes use of the ternary operator Actually, no... my solution is the correct one. Yours will echo the error span whether or not there is an error. Wrong place for a ternary. Your original code was wrong (which is why OP said it didn't work). You've since edited it to be more correct. An empty span won't render or take up space, so it doesn't matter in the long run. Plus, some JS error handling requires the error span to already be present in order to be populated, so it's a good idea to have it there in case it's needed. Link to comment https://forums.phpfreaks.com/topic/263376-undefined-index-message/#findComment-1349992 Share on other sites More sharing options...
smoseley Posted May 31, 2012 Share Posted May 31, 2012 The solution to bad code is NEVER "turn off error reporting." Fix your code. Fix your code like this: <?php echo "<span class=\"error\">".(isset($_GET['message']) ? $_GET['message'] : '')."</span>"; ?> This snippet makes use of the ternary operator Actually, no... my solution is the correct one. Yours will echo the error span whether or not there is an error. Wrong place for a ternary. Your original code was wrong (which is why OP said it didn't work). You've since edited it to be more correct. An empty span won't render or take up space, so it doesn't matter in the long run. Plus, some JS error handling requires the error span to already be present in order to be populated, so it's a good idea to have it there in case it's needed. Umm, no... I edited my post 2 minutes after I posted it. Look again. The OP must have used the wrong snippet, because my code is perfect. FYI, my edit was to change my reply from your exact solution (a ternary on the content) to an if... then. Because I realized a ternary approach would still render the span. The empty <span class="error"> wouldn't render anything? You know better.... Common CSS for errors is to wrap it in a box: span.error { display: block; border: 1px solid #f00; padding: 10px; margin: 10px 0; color: #f00; background-color: #fee; font-weight: bold; } Link to comment https://forums.phpfreaks.com/topic/263376-undefined-index-message/#findComment-1350001 Share on other sites More sharing options...
ManiacDan Posted May 31, 2012 Share Posted May 31, 2012 The empty <span class="error"> wouldn't render anything?Exactly 100% true. Common CSS for errors is to wrap it in a box:Ok, you got me. DRAWING A BOX AROUND AN INVISIBLE SPAN would make it visible. Congratulations, you've won. Link to comment https://forums.phpfreaks.com/topic/263376-undefined-index-message/#findComment-1350063 Share on other sites More sharing options...
Recommended Posts