title: PHP - Notice: Undefined index:
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index">PHP: “Notice: Undefined variable”  and “Notice: Undefined index”</a>  </p>
  </blockquote>
  
  
  
  <p>I am trying to do a registration form that registers a user in a database (MySQL).</p>
  
  <p>The code is supposed to register:</p>
  
  <ul>
  <li>Name</li>
  <li>Surname</li>
  <li>Username</li>
  <li>Password</li>
  <li>Email</li>
  <li>Security Question</li>
  <li>Security Answer</li>
  </ul>
  
  <p>The code, before saving to the table, checks whether the username or password already exists, and if they do it echoes an error message, and if not, it saves to the db.</p>
  
  <p>However, on page load, I'm getting these errors:</p>
  
  <pre><code>Notice: Undefined index: Name in C:\xampp\htdocs\Task2\registration.php on line 216
  
  Notice: Undefined index: Surname in C:\xampp\htdocs\Task2\registration.php on line 217
  
  Notice: Undefined index: Username in C:\xampp\htdocs\Task2\registration.php on line 219
  
  Notice: Undefined index: Email in C:\xampp\htdocs\Task2\registration.php on line 221
  
  Notice: Undefined index: C_Email in C:\xampp\htdocs\Task2\registration.php on line 222
  
  Notice: Undefined index: password in C:\xampp\htdocs\Task2\registration.php on line 224
  
  Notice: Undefined index: c_password in C:\xampp\htdocs\Task2\registration.php on line 225
  
  Notice: Undefined index: SecQ in C:\xampp\htdocs\Task2\registration.php on line 227
  
  Notice: Undefined index: SecA in C:\xampp\htdocs\Task2\registration.php on line 228
  
  Notice: Undefined variable: mysql_connect in C:\xampp\htdocs\Task2\registration.php on line 231
  
  Fatal error: Function name must be a string in C:\xampp\htdocs\Task2\registration.php on line 231
  </code></pre>
  
  <p>This is the code:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  
    &lt;title&gt;Registration&lt;/title&gt;
  
    &lt;style type="text/css" title="Amaya theme"&gt;
  
  body {
      font-size: 12pt;
      font-family: Helvetica, Arial, sans-serif;
      font-weight: normal;
      font-style: normal;
      color: black;
      background-color: white;
      line-height: 1.2em;
      margin-left: 4em;
      margin-right: 2em;
     }
  
  /* paragraphs */
  p  {
      padding: 0;
      margin-top: 1em;
      margin-bottom: 1em;
      text-align: left;
     }
  
  /* headings */
  h1 {
      font-size: 180%;
      font-weight: bold;
      font-style: normal;
      font-variant: small-caps;
      text-align: left;
      padding: 0;
      margin-top: 1.7em;
      margin-bottom: 1.7em;
     }
  h2 {
      font-size: 150%;
      font-weight: bold;
      font-style: normal;
      padding: 0;
      margin-top: 1.5em;
      margin-bottom: 1.1em;
     }
  h3 {
      font-size: 130%;
      font-weight: bold;
      font-style: normal;
      padding: 0;
      margin-top: 1.3em;
      margin-bottom: 1.1em;
     }
  h4 {
      font-size: 110%;
      font-weight: bold;
      font-style: normal;
      padding: 0;
      margin-top: 1.1em;
      margin-bottom: 1.1em;
     }
  h5 {
      font-size: 100%;
      font-weight: bold;
      font-style: italic;
      padding: 0;
      margin-top: 1em;
      margin-bottom: 1em;
     }
  h6 {
      font-size: 100%;
      font-weight: normal;
      font-style: italic;
      padding: 0;
      margin-top: 1em;
      margin-bottom: 1em;
     }
  
  /* divisions */
  div {
      padding: 0;
      margin-top: 0em;
      margin-bottom: 0em;
     }
  
  /* lists */
  ul, ol {
      padding: 0 0 0 3em;
      margin-top: 1em;
      margin-bottom: 1em;
     }
  ul ul, ol ol, ul ol, ol ul {
      margin-top: 1em;
      margin-bottom: 1em;
     }
  li {
      padding: 0;
      margin-top: 1em;
      margin-bottom: 1em;
      text-align: left;
     }
  li p {
      margin-top: 1em;
      margin-bottom: 1em;
     }
  dl {
      padding: 0;
      margin-top: 1em;
      margin-bottom: 1em;
      margin-left: 1em;
     }
  dl dl {
      margin-top: 0em;
      margin-bottom: 0em;
     }
  dt {
      padding: 0;
      font-weight: bold;
      margin-top: .3em;
      margin-bottom: .3em;
     }
  dd {
      padding: 0;
      margin-top: .3em;
      margin-left: 3em;
      margin-bottom: .3em;
     }
  dl p {
      margin-top: .3em;
      margin-bottom: .3em;
     }
  
  /* inline */
  strong {
      font-weight: bold;
     }
  em {
      font-style: italic;
     }
  code {
      font-family: Courier New, Courier, monospace;
     }
  ins {
      background-color: yellow;
      text-decoration: underline;
     }
  del {
      text-decoration: line-through;
     }
  
  
  a[href] {
      color: blue;
      text-decoration: underline;
     }
  
  
    &lt;/style&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;h4&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif"&gt;Name&lt;/span&gt;&lt;/h4&gt;
  
  &lt;p style="font-family: Arial,Helvetica,sans-serif"&gt; &lt;input type="text"  name='Name'/&gt;&lt;/p&gt;
  
  &lt;h4 style="font-family: Arial,Helvetica,sans-serif"&gt;Surname&lt;/h4&gt;
  
  &lt;p style="font-family: Arial,Helvetica,sans-serif"&gt; &lt;input type="text" name='Surname'/&gt;&lt;/p&gt;
  
  &lt;h4 style="font-family: Arial,Helvetica,sans-serif"&gt;Username&lt;/h4&gt;
  
  &lt;p style="font-family: Arial,Helvetica,sans-serif"&gt; &lt;input type="text" name='Username' /&gt;&lt;/p&gt;
  &lt;hr style="font-family: Arial,Helvetica,sans-serif" /&gt;
  
  &lt;h4 style="font-family: Arial,Helvetica,sans-serif"&gt;Email&lt;/h4&gt;
  
  &lt;p style="font-family: Arial,Helvetica,sans-serif"&gt; &lt;input type="text" name='Email' /&gt;&lt;/p&gt;
  
  &lt;h4 style="font-family: Arial,Helvetica,sans-serif"&gt;Confirm Email&lt;/h4&gt;
  
  &lt;p style="font-family: Arial,Helvetica,sans-serif"&gt; &lt;input type="text" name='C_Email' /&gt;&lt;/p&gt;
  &lt;hr style="font-family: Arial,Helvetica,sans-serif" /&gt;
  
  &lt;h4 style="font-family: Arial,Helvetica,sans-serif"&gt;Password&lt;/h4&gt;
  
  &lt;p style="font-family: Arial,Helvetica,sans-serif"&gt; &lt;input type="password" name='password' /&gt;&lt;/p&gt;
  
  &lt;h4 style="font-family: Arial,Helvetica,sans-serif"&gt;Confirm Password&lt;/h4&gt;
  
  &lt;p style="font-family: Arial,Helvetica,sans-serif"&gt; &lt;input type="password" name='c_password'/&gt;&lt;/p&gt;
  &lt;hr style="font-family: Arial,Helvetica,sans-serif" /&gt;
  
  &lt;h4 style="font-family: Arial,Helvetica,sans-serif"&gt;Security Question&lt;/h4&gt;
  
  &lt;p style="font-family: Arial,Helvetica,sans-serif"&gt; &lt;input type="password" name='SecQ' /&gt;&lt;/p&gt;
  
  &lt;h4 style="font-family: Arial,Helvetica,sans-serif"&gt;Security Answer&lt;/h4&gt;
  
  &lt;p style="font-family: Arial,Helvetica,sans-serif"&gt; &lt;input type="password" name='SecA'/&gt;&lt;/p&gt;
  &lt;hr style="font-family: Arial,Helvetica,sans-serif" /&gt;
  
  &lt;hr style="font-family: Arial,Helvetica,sans-serif" /&gt;
  
  
  &lt;p&gt;&lt;span
  style="font-family: Arial,Helvetica,sans-serif"&gt;&lt;button&gt;Submit&lt;/button&gt;&lt;/span&gt;&lt;/p&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  &lt;?php
  $Name = $_POST['Name'];
  $Surname = $_POST['Surname'];
  
  $Username = $_POST['Username'];
  
  $Email = $_POST['Email'];
  $C_Email = $_POST['C_Email'];
  
  $Password = $_POST['password'];
  $C_Password = $_POST['c_password'];
  
  $SecQ = $_POST['SecQ'];
  $SecA = $_POST['SecA'];
  
  
  $mysql_connect ('localhost', 'admin', 'storefile1234');
  mysql_select_db ("storefile");
  
  $check_username = mysql_query("SELECT FROM users WHERE username = '$Username'");
  $check_email = mysql_query("SELECT FROM users WHERE email = '$Email'");
  
  
  if ($Name == null || $Surname== null || $Username == null || $Password == null || $C_Password == null || $Email == null || $C_Email == null || $SecQ == null || $SecA == null ) {
  
      echo "Missing details. Please enter all fields.";
  
  
  } else {
  
      if(mysql_num_rows($check_username) != 0 &amp;&amp; mysql_num_rows($check_email) != 0)
              {
              echo "Username/Email already exists";
              }
              if  ($Email == $C_Email &amp;&amp; $Password == $C_Password) {
  
                  $query = "INSERT INTO users (Username, Name,Surname, Password, Email, SecQ, SecA) VALUES ('NULL', ".$Username."', ".$Name."', ".$Surname."', ".$Password."', ".$SecQ."', ".$SecA."', ".$Email.')"';
  
                  mysql_query($query) or die ('Error registering.');
  
                  echo "Greetings, ".$Name.", you have been registered. ";
  
      }  else {
  
          echo "Error registering your account. Please try again.";
              }
  
   }
  
  
  ?&gt;
  </code></pre>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks!</p>