0

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>
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by stefh
0

Hi,

try this way instead:

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

    // put your code there...

}
?>

Edited by stefh: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.