Jump to content

Undefined index: message


KANJE

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.