Hello, I am fairly new to PHP and I am working on a Registration script but I get the following error and I don't know what is causing it.

Undefined index: submit in C:\wamp\www\registerNEW.php on line 7

<?php

include_once "functionsNEW.php";

connect();

if(!$_POST['submit'])
{
	echo	"<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">";
	echo	"<form method=\"Post\" action=\"Register.php\">";
	echo	"<tr><td colspan=\"2\" align=\"center\"><b>Registration Form</b></td></tr>";
	echo	"<tr><td>Username</td><td><input type=\"text\" Name=\"Username\"></td></tr>";
	echo	"<tr><td>Password</td><td><input type=\"password\" Name=\"Password\"></td></tr>";
	echo	"<tr><td>Confirm</td><td><input type=\"password\" Name=\"Passconf\"></td></tr>";
	echo	"<tr><td>E-Mail Address</td><td><input type=\"text\" Name=\"email\"></td></tr>";
	echo	"<tr><td>Name</td><td><input type=\"text\" Name=\"Name\"></td></tr>";
	echo	"<tr><td colspan=\"2\" Align=\"Center\"><input type=\"Submit\" Name=\"Submit\" Value=\"Register\"></td></tr>";
	echo	"</form></table>";	
}

else 

{
    $username = protect($_POST['username']);
    $password = protect($_POST['password']);
    $confirm = protect($_POST['passconf']);
    $email = protect($_POST['email']);
    $name = protect($_POST['name']);


$errors = array();

    if(!$username){
        $errors[] = "Username is not defined!";
    }

    if(!$password){
        $errors[] = "Password is not defined!";
    }

    if($password){
        if(!$confirm){
            $errors[] = "Confirmation password is not defined!";
        }
    }

    if(!$email){
        $errors[] = "E-mail is not defined!";
    }

    if(!$name){
        $errors[] = "Name is not defined!";
    }


    if($username){
        if(!ctype_alnum($username)){
            $errors[] = "Username can only contain numbers and letters!";
        }

        $range = range(1,32);
        if(!in_array(strlen($username),$range)){
            $errors[] = "Username must be between 1 and 32 characters!";
        }
    }

    if($password && $confirm){
        if($password != $confirm){
            $errors[] = "Passwords do not match!";
        }
    }

    if($email){
        $checkemail = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
        if(!preg_match($checkemail, $email)){
            $errors[] = "E-mail is not valid, must be name@server.tld!";
        }
    }

    if($name){
        $range2 = range(3,64);
        if(!in_array(strlen($name),$range2)){
            $errors[] = "Your name must be between 3 and 64 characters!";
        }
    }

    if($aim){
        $range3 = range(3,16);
        if(!in_array(strlen($aim),$range3)){
            $errors[] = "Your AIM screenname must be between 3 and 16 characters!";
        }
    }

    if($username){
        $sql = "SELECT * FROM `users` WHERE `username`='".$username."'";
        $res = mysql_query($sql) or die(mysql_error());

            if(mysql_num_rows($res) > 0){
                $errors[] = "The username you supplied is already in use!";
            }
    }

    if($email){
        $sql2 = "SELECT * FROM `users` WHERE `email`='".$email."'";
        $res2 = mysql_query($sql2) or die(mysql_error());

            if(mysql_num_rows($res2) > 0){
                $errors[] = "The e-mail address you supplied is already in use of another user!";
            }
    }


    if(count($errors) > 0){
        foreach($errors AS $error){
            echo $error . "<br>\n";
        }
    }else {
        $sql4 = "INSERT INTO `users`
                (`username`,`password`,`email`,`name`,`admin`,`time`)
                VALUES ('".$username."','".md5($password)."','".$email."','".$name."','".$aim."','0','".time()."')";
        $res4 = mysql_query($sql4) or die(mysql_error());
        echo "You have successfully registered with the username <b>".$username."</b> and the password of <b>".$password."</b>!";
    }
}
/**
 * @author D.Helsdon
 * @copyright 2009
 */



?>

    Check to see if it's set:

    if (!isset($_POST['submit']) || ($POST['submit'] != 'Register'))

      Great, Thanks for your help.
      I replaced

      <?php
      
      include_once "functionsNEW.php";
      
      
      connect();
      
      if ($_POST['submit']) 
      

      With...

      <?php
      
      include_once "functionsNEW.php";
      
      
      connect();
      
      if (!isset($_POST['submit']) || ($POST['submit'] != 'Register'))
      

        Hmm.. It seems to be overriding the rest of the actual registration process,
        If I fill out the form and press register the form is cleared.. no visible info added to mysql database: Users

          Change $POST['submit'] to $POST['Submit'].

            Okay, so I am a bit confused.. do I use both

            if ($_POST['Submit'])
            if (!isset($_POST['Submit']) || ($POST['Submit'] != 'Register'))
            

            Or just one, because If I only use ($_POST['Submit']) then I get no errors, but I also have no successful registration.

            If I use if (!isset($_POST['Submit']) || ($POST['Submit'] != 'Register')) then I get an undefined variable: POST

              My fault, another typo.

              Use only this line:

              if (!isset($_POST['Submit']) || ($_POST['Submit'] != 'Register'))

              I don't think there are any typos there, but if there are, I'm going to leave it to you to catch the more obvious ones.

                if ($_POST['submit'])   

                This would succeed is $_POST['submit'] is set, and fail it if it's not.

                 if (!isset($_POST['Submit']) || ($_POST['Submit'] != 'Register')) 

                This would succeed if $_POST['submit'] is not set - or if it is set but to something other than 'Register'.

                  This would succeed if $_POST['submit'] is not set - or if it is set but to something other than 'Register'.

                  ...which seems to be the desired behavior.

                  BTW, you might find this more readable, as I do:

                  echo '<table border="0" cellspacing="3" cellpadding="3">'; 
                   echo '<form method="Post" action="index.php">'; 
                   echo '<tr><td colspan="2" align="center"><b>Registration Form</b></td></tr>'; 
                   echo '<tr><td>Username</td><td><input type="text" Name="Username"></td></tr>'; 
                   echo '<tr><td>Password</td><td><input type="password" Name="Password"></td></tr>'; 
                   echo '<tr><td>Confirm</td><td><input type="password" Name="Passconf"></td></tr>'; 
                   echo '<tr><td>E-Mail Address</td><td><input type="text" Name="email"></td></tr>'; 
                   echo '<tr><td>Name</td><td><input type="text" Name="Name"></td></tr>'; 
                   echo '<tr><td colspan="2" Align="Center"><input type="Submit" Name="Submit" Value="Register"></td></tr>'; 
                   echo '</form></table>';

                    Okay so the Registration form works great now, but I am having an issue with the login form..

                    There is always this error showing up when I am on the index.php, and on login.php

                    Notice: Undefined index: uid in C:\website\wamp\www\Forum\index.php on line 49
                    Notice: Undefined index: uid in C:\website\wamp\www\Forum\login.php on line 7

                    I thought I used my database to define uid..

                    ALSO - It seems my login page isn't doing anything when I proceed with a login, using a correct login, and an incorrect login.. it isn't displaying any warnings about blank fields like it should.

                    LOGIN.PHP

                    <?php
                    session_start();
                    include "./global.php";
                    
                    echo "<title>Login</title>";
                    
                    if ($_SESSION['uid']) {
                    	echo "You are already logged in, if you wish to log out please <a href=\"./logout.php\">click here</a>!/\n";
                    }else{
                    
                    if ($_POST['submit']){
                    	echo '<table border="0" cellspacing="3" cellpadding="3">';
                    	echo '<form method="Post" action="./login.php">';
                    	echo '<tr><td>Username</td><td><input type="text" name="username"></td></tr>';
                    	echo '<tr><td>Password</td><td><input type="password" name="password"></td></tr>';
                    	echo '<tr><td colspan="2" align="right"><input type="submit" name="submit"></td></tr>';
                    	echo '</form></table>';  
                    }else{ $user = mss($_POST['username']); $pass = $_POST['password']; if($user && $pass){ $sql = "SELECT id FROM 'users' WHERE 'username'='".$user."'"; $res = mysql_query($sql) or die (mysql_error()); if (mysql_num_rows($res) > 0){ $sql2 = "SELECT id FROM 'users' WHERE 'username'='".$user."' AND 'password'='".md5($pass)."'"; $res2 = mysql_query($sql2) or die (mysql_error()); if(mysql_num_rows($res2) > 0){ $row = mysql_fetch_assoc($res2); $_SESSION['uid'] = $row['id']; echo "You have successfully logged in as " . $user; }else{ echo "Your Username and Password do not match!\n"; } }else{ echo "The username you provided does not exist!\n"; } }else{ echo "You must enter a valid username and password!\n"; } } } ?>

                    I tried switching the $_POST['submit'] like we had done on the registration page, that still seems to have no effect on the actual login.

                      Write a Reply...