Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[PHP] form $_POST

Status
Not open for further replies.
Newbie Spellweaver
Joined
Nov 19, 2008
Messages
50
Reaction score
2
i'm not whats wrong now? i get this error:

Notice: Undefined index: submit in C:\wamp\www\Projects\Css_hjemmeside\register.php on line 3

Notice: Undefined index: navn in C:\wamp\www\Projects\Css_hjemmeside\register.php on line 4

Notice: Undefined index: username in C:\wamp\www\Projects\Css_hjemmeside\register.php on line 5

Notice: Undefined index: password in C:\wamp\www\Projects\Css_hjemmeside\register.php on line 6

Notice: Undefined index: repeatpassword in C:\wamp\www\Projects\Css_hjemmeside\register.php on line 7


<?php
echo "register";
$submit = $_POST['submit'];
$navn = $_POST['navn'];
$username = $_POST['username'];
$password = $_POST['password'];
$repeatpassword = $_POST['repeatpassword'];

if ($submit)
{


}

?>

<html>

<form action='register.php' methot='POST'>
<table>
<tr>
<td>
Dit navn:
</td>
<td>
<input type='text' name='navn'>
</td>
</tr>
<tr>
<td>
Brugernavn:
</td>
<td>
<input type='text' name='username'>
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type='password' name='password'>
</td>
</tr>

<tr>
<td>
Password:
</td>
<td>
<input type='password' name='repeatpassword'>
</td>
</tr>

</table>
<input type='submit' name='submit' value='Register'>
</form>

</html>
 
Last edited:
Newbie Spellweaver
Joined
Nov 19, 2008
Messages
50
Reaction score
2
I still get the dam message:

<?php
echo "register<br>";
$submit = $_POST['submit'];
$navn = strip_tags($_POST['navn']);
$username = strip_tags($_POST['username']);
$password = strip_tags($_POST['password']);
$repeatpassword = strip_tags($_POST['repeatpassword']);

$data = date("Y-m-d");
if ($submit)
{
if ($navn&&$username&&$password&&$repeatpassword)
{
$password = md5($password);
$repeatpassword = md5($repeatpassword);

if ($password==$repeatpassword)
{
if (strlen($username)>25||strlen($navn)>25)
{
echo "Dit brugernavn eller navn er for langt.";
}
else
{
if (strlen($password)>25||strlen($password)<6)
{
echo "Dit password må kun være mellem 6 og 25 bogstaver eller tal.";
}
else
{



}



}




}
else
echo "Dine password passer ikke sammen.";


}
else
echo"Du har ikke udfyldt alle felterne";


}

?>

<html>

<form action='register.php' method='POST'>
<table>
<tr>
<td>
Dit navn:
</td>
<td>
<input type='text' name='navn'>
</td>
</tr>
<tr>
<td>
Brugernavn:
</td>
<td>
<input type='text' name='username'>
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type='password' name='password'>
</td>
</tr>

<tr>
<td>
Password:
</td>
<td>
<input type='password' name='repeatpassword'>
</td>
</tr>

</table>
<input type='submit' name='submit' value='Register'>
</form>

</html>
 
Custom Title Activated
Loyal Member
Joined
May 18, 2006
Messages
2,065
Reaction score
14
Code:
<?php
if (isset($_POST['submit']))
{

// Put your entire PHP code here

}
?>
 
(oO (||||) (||||) Oo)
Loyal Member
Joined
Aug 6, 2009
Messages
2,132
Reaction score
429
If you do not know even a simple thing like a post then you shouldn't be coding.

Example of form that I use:
PHP:
<? if (isset($_POST['Submit'])) {
					
					$username	= mysql_real_escape_string($_POST['username']);
					$password	= mysql_real_escape_string($_POST['password']);
					$password2	= mysql_real_escape_string($_POST['password2']);
					$email		= mysql_real_escape_string($_POST['email']);
					$ip			= $_SERVER['REMOTE_ADDR'];
					
					$query = "SELECT * FROM accounts WHERE username='".strtolower($username)."';";
					$query2 = "SELECT * FROM accounts WHERE lastip='".$ip."';";
					$res = mysql_query($query);
					$res2 = mysql_query($query2);
					
					if(empty($username) || $username == "")
					{
						echo "Username field is empty";
						echo "<br /><a onclick='history.back();' href='#'>Go back</a>";
					}
					elseif(empty($password) || $password == "")
					{
						echo "Password field is empty";
						echo "<br /><a onclick='history.back();' href='#'>Go back</a>";
					}
					elseif(empty($password2) || $password2 == "")
					{
						echo "Password confirmation field is empty";
						echo "<br /><a onclick='history.back();' href='#'>Go back</a>";
					}
					elseif(empty($email) || $email == "")
					{
						echo "EMail field is empty";
						echo "<br /><a onclick='history.back();' href='#'>Go back</a>";
					}
					elseif(strlen($username) > 10)
					{
						echo "Username can't be longer than 10 characters";
						echo "<br /><a onclick='history.back();' href='#'>Go back</a>";
					}
					elseif(strlen($username) < 4)
					{
						echo "Username can't be smaller than 4 characters";
						echo "<br /><a onclick='history.back();' href='#'>Go back</a>";
					}
					elseif(strlen($password) > 10)
					{
						echo "Password can't be longer than 10 characters";
						echo "<br /><a onclick='history.back();' href='#'>Go back</a>";
					}
					elseif(strlen($password) < 4)
					{
						echo "Password can't be smaller than 4 characters";
						echo "<br /><a onclick='history.back();' href='#'>Go back</a>";
					}
					elseif(strlen($email) > 60)
					{
						echo "Email can't be longer than 60 characters";
						echo "<br /><a onclick='history.back();' href='#'>Go back</a>";
					}
					elseif(!isAlphaNumeric($username))
					{
						echo "Username can be alphanumeric only. It means it can have letters and numbers in it only.";
						echo "<br /><a onclick='history.back();' href='#'>Go back</a>";
					}
					elseif($password != $password2)
					{
						echo "Passwords do not match";
						echo "<br /><a onclick='history.back();' href='#'>Go back</a>";
					}
					elseif(mysql_num_rows($res) > 0)
					{
						echo "Sorry such account already exist.";
						echo "<br /><a onclick='history.back();' href='#'>Go back</a>";
					}
					elseif(mysql_num_rows($res2) > 2)
					{
						echo "Sorry you can have only 3 accounts per IP.";
						echo "<br /><a onclick='history.back();' href='#'>Go back</a>";
					}
					else
					{
						$insertUser = mysql_query("INSERT INTO `accounts`(username,password,email) VALUES ('".strtolower($username)."', '".md5($password)."', '$email');");
						
						if($insertUser)
						{
							echo "Account has been created. Enjoy :)";
							echo "<br /><br />";
							echo "<h2>Account information</h2>";
							echo "Username: " . strtolower($username) . " (all lower case) <br />";
							echo "Password: " . $password . " (case sensative) <br />";
							echo "Email: " . $email . " (used to restore/change password) <br />";
						}
						else
						{
							echo "Strange error occured. Please contact administrator";
						}
					}
				} else {
				?>
				
				<p>
					<form action="index.php?id=registration" method="post">
						<table border="0" width="100%">
							<tr>
								<td>Username:</td>
								<td><input type="text" name="username"></td>
							</tr>
							<tr>
								<td>Password:</td>
								<td><input type="password" name="password"></td>
							</tr>
							<tr>
								<td>Password confirmation:</td>
								<td><input type="password" name="password2"></td>
							</tr>
							<tr>
								<td>Email:</td>
								<td><input type="text" name="email"></td>
							</tr>
							<tr>
								<td><input type="reset" name="Clear" value="Clear"></td>
								<td><input type="submit" name="Submit" value="Create account"></td>
							</tr>
						</table>
					</form>
				</p>
				
				<? } ?>

You can use following instead of "elseif"
PHP:
if (condition)
{
// Code here
}
else
{
    if (condition2)
    {
    // do another code here
    }
    else
    {
         if (condition3)
         { 
         // do another thing
         }
         else
         {
         // and so on
         }
    }
}
 
Ginger by design.
Loyal Member
Joined
Feb 15, 2007
Messages
2,340
Reaction score
653
Don't type in help sestion if you don't help.

I pay for my bandwidth.

You post 50845690840689405860456804686 threads asking mundane questions about PHP that could be answered by spending 20 minutes reading the Ducking manual.

So I load the coder forum and as such am inundated with shenanigans created by you to do your work for you, which had you had even an IQ of 80 would've been able to figure out yourself.

As such, following from the first statement, you owe me money for wasting the bandwidth I pay for.

Thanks much, moron.
 
Joined
Mar 26, 2006
Messages
598
Reaction score
4
I pay for my bandwidth.

You post 50845690840689405860456804686 threads asking mundane questions about PHP that could be answered by spending 20 minutes reading the Ducking manual.

So I load the coder forum and as such am inundated with shenanigans created by you to do your work for you, which had you had even an IQ of 80 would've been able to figure out yourself.

As such, following from the first statement, you owe me money for wasting the bandwidth I pay for.

Thanks much, moron.

Does it honestly matter if you pay for bandwith? Doesn't give you extra rights to spam, flame, or break the rules. Although yes I do understand you and why your aggravated. Still doesn't give you extra rights so get over it?

And back on topic. Your setting vars before they're defined.
PHP:
<?PHP
if(isset($_POST['submit'])) {
$register = $_POST['register'];
//Continue vars here. And continue your script.
}
?>
//Then your form will go here with the method = "post".
//Could also do action = "<?PHP $_SERVER['PHP_SELF']; ?>";
//Your choice. Either way its going to give you the same results.
Although next time, read some tutorials through possibly w3 schools. Or even tizag, they have some great beginner references.
 
Last edited:
Vous Pas Reel
Loyal Member
Joined
Nov 6, 2007
Messages
880
Reaction score
11
Means they have no valu so you might of put the wrong I'd in the forms
 
C# Developer
Joined
Jan 27, 2008
Messages
541
Reaction score
12
I pay for my bandwidth.

You post 50845690840689405860456804686 threads asking mundane questions about PHP that could be answered by spending 20 minutes reading the Ducking manual.

So I load the coder forum and as such am inundated with shenanigans created by you to do your work for you, which had you had even an IQ of 80 would've been able to figure out yourself.

As such, following from the first statement, you owe me money for wasting the bandwidth I pay for.

Thanks much, moron.

If your expecting anything different from a coding forum, i must say that you are the moron.
 
Joined
Nov 17, 2008
Messages
800
Reaction score
1,392
Re: Study allowed a trial

----------------------Information Bar-----------------------
-----------------------------------------------------------------

What the duck does this even mean?

ONTOPIC:

I want you guys to realize that, with the right terminology in your search, Google can literally find almost everything you need to find. I promise you this.
 
Ginger by design.
Loyal Member
Joined
Feb 15, 2007
Messages
2,340
Reaction score
653
If your expecting anything different from a coding forum, i must say that you are the moron.

Most forums ban people who repeatedly ask stupid questions (questions solved by a quick google, or Ring TFM). Feel free to check the board rules as well. It's pretty clearly stated.

Also, people who fail to make grammatically correct posts while criticizing others typically are ridiculed.
 
Legendary Battlemage
Joined
Aug 16, 2008
Messages
600
Reaction score
259
PHP:
<?php
if(isset($_POST['submit']))
{
	$errors = array();
	
	if (strlen($_POST['password']) < 6 || strlen($_POST['password']) > 50)
	{
		$errors[] = "Please enter a password with a minimum of six characters.";
	}
	else if ($_POST['password'] !== $_POST['repeatpassword'])
	{
		$errors[] = "Please make sure both passwords match.";
	}
	
	if (count($errors) == 0)
	{
		/* Create fields? */
	}
	
	if (count($errors) > 0)
	{
		foreach ($errors as $error)
		{
			$error = '<b>'.$error.'</b><br />';
		}
	}
}
?>
<!DOCTYPE html>
	<head>
		<title>Register</title>
	</head>
	<body>
		<h1>Register</h1>
		<?php echo $error; ?>
		<form action="" method="post">
			<table>
				<tbody>
					<tr>
						<td>
							Dit navn:
						</td>
						<td>
							<input type="text" name="navn" />
						</td>
					</tr>
					<tr>
						<td>
							Brugernavn:
						</td>
						<td>
							<input type="text" name="username" />
						</td>
					</tr>
					<tr>
						<td>
							Password:
						</td>
						<td>
							<input type="password" name="password" />
						</td>
					</tr>
					<tr>
						<td>
							Password:
						</td>
						<td>
							<input type="password" name="repeatpassword" />
						</td>
					</tr>
				</tbody>
			</table>
			<input type="submit" name="submit" value="Register" />
		</form>
	</body>
</html>

You're welcome.
 
Joined
Jun 8, 2007
Messages
1,985
Reaction score
490
Maybe because everybody is replying and it stays at the top, and everyone knows how to use $_POST and comes here to get disappointed more than once...
 
Experienced Elementalist
Joined
Oct 9, 2007
Messages
248
Reaction score
80
Code:
[COLOR=#333333]<?php[/COLOR]
[COLOR=#333333]echo "register";[/COLOR]
[COLOR=#333333]$submit = @$_POST['submit'];[/COLOR]
[COLOR=#333333]$navn = @$_POST['navn'];[/COLOR]
[COLOR=#333333]$username = @$_POST['username'];[/COLOR]
[COLOR=#333333]$password = @$_POST['password'];[/COLOR]
[COLOR=#333333]$repeatpassword = @$_POST['repeatpassword'];[/COLOR]

[COLOR=#333333]if ($submit)[/COLOR]
[COLOR=#333333]{[/COLOR]


[COLOR=#333333]}[/COLOR]

[COLOR=#333333]?>[/COLOR]

[COLOR=#333333]<html>[/COLOR]

[COLOR=#333333]<form action='register.php' [/COLOR][COLOR=#000000]method[/COLOR][COLOR=#333333]='POST'>[/COLOR]
[COLOR=#333333]<table>[/COLOR]
[COLOR=#333333]<tr>[/COLOR]
[COLOR=#333333]<td>[/COLOR]
[COLOR=#333333]Dit navn:[/COLOR]
[COLOR=#333333]</td>[/COLOR]
[COLOR=#333333]<td>[/COLOR]
[COLOR=#333333]<input type='text' name='navn'>[/COLOR]
[COLOR=#333333]</td>[/COLOR]
[COLOR=#333333]</tr>[/COLOR]
[COLOR=#333333]<tr>[/COLOR]
[COLOR=#333333]<td>[/COLOR]
[COLOR=#333333]Brugernavn:[/COLOR]
[COLOR=#333333]</td>[/COLOR]
[COLOR=#333333]<td>[/COLOR]
[COLOR=#333333]<input type='text' name='username'>[/COLOR]
[COLOR=#333333]</td>[/COLOR]
[COLOR=#333333]</tr>[/COLOR]
[COLOR=#333333]<tr>[/COLOR]
[COLOR=#333333]<td>[/COLOR]
[COLOR=#333333]Password:[/COLOR]
[COLOR=#333333]</td>[/COLOR]
[COLOR=#333333]<td>[/COLOR]
[COLOR=#333333]<input type='password' name='password'>[/COLOR]
[COLOR=#333333]</td>[/COLOR]
[COLOR=#333333]</tr>[/COLOR]

[COLOR=#333333]<tr>[/COLOR]
[COLOR=#333333]<td>[/COLOR]
[COLOR=#333333]Password:[/COLOR]
[COLOR=#333333]</td>[/COLOR]
[COLOR=#333333]<td>[/COLOR]
[COLOR=#333333]<input type='password' name='repeatpassword'>[/COLOR]
[COLOR=#333333]</td>[/COLOR]
[COLOR=#333333]</tr>[/COLOR]

[COLOR=#333333]</table>[/COLOR]
[COLOR=#333333]<input type='submit' name='submit' value='Register'>[/COLOR]
[COLOR=#333333]</form>[/COLOR]

[COLOR=#333333]</html>

use if ...[/COLOR]
 
Status
Not open for further replies.
Back
Top