Hi im new to php and i have been following along on a video on how to create a registration form, but im getting an error "Notice: Undefined index: button in E:\EasyPHP-5.3.2i\www\Survey\register.php on line 3" Please help im new to php and don't know much

Here is the code:

<?php

$button = $_POST['button'];

if ($button)
{   
	// get data 
    $username = $_POST['username'];
	$password = $_POST['password'];
	$retypepassword = $_POST['password'];
	$email = $_POST['email'];
	
	if($username && $password && $retypepassword && $email)
	{
	    if ($password == $retypepassword)
		{
			if (strstr($email, "@") && strstr($email, "@"))
			{
				include ("connect.php");
				$query = mysql_query ("SELECT * FROM users WHERE username='$username'");
				$numrows = mysql_num_rows($query);
				if ($numrows == 0)
				{
					$password = md5($password);
					
					$register = mysql_query("INSERT INTO users VALUES ('', '$username', '$password' '$email')");
					
					echo "You have been registered.";
					
				}

				else
					echo "That username is taken";
			}
			else
				echo "Not a valid email";
		}
		else
			echo "Passwords did not match";
		
	}
	
	else
	    echo "You did not fill in every field";
	
	
}
else
{
    echo "
	<form action'register.php' method='POST'>
<table width='500'>
<tr>
  <td align='right'>Username:</td>
  <td align='left'><Input type='text' name='username'></td>
</tr>
<tr>
  <td align='right'>Password:</td>
  <td align='left'><Input type='password' name='password'></td>
</tr>
<tr>
  <td align='right'>Retype Password:</td>
  <td align='left'><Input type='password' name='retypepassword'></td>
</tr>
<tr>
  <td align='right'>Email:</td>
  <td align='left'><Input type='text' name='email'></td>
</tr>
<tr>
  <td align='right'></td>
  <td align='left'><Input type='submit' name='button' value='Register'></td>
</tr>
</table></form>
	";
}

?>

<html>



</html>

Hi,

try this way instead:

<?php
if (isset($_POST['button'])) {

    // put your code there...

}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.