Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

checking if forms are filled on submission

$
0
0

Here is my html form and my php code. It is supposed to check if any of the forms have not been filled and echo a message if they have not. Then process the registration if they have. But it seems to ignore the blank spots. If I don't fill in fields it just processes the blank registration anyways. Where did I go wrong?

<?php
include ('config.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	$username = mysql_real_escape_string($_POST['username']);
	$password = mysql_real_escape_string(md5($_POST['password']));
	$firstname = mysql_real_escape_string($_POST['firstname']);
	$lastname = mysql_real_escape_string($_POST['lastname']);
	$email = mysql_real_escape_string($_POST['email']);

if (!isset($username) || !isset($password) || !isset($firstname) || !isset($lastname) || !isset($email) ) {
	echo "You did not fill out the required fields.";
} else {
		$query = mysql_query("SELECT * FROM users WHERE username = '$username'");
		$rows = mysql_num_rows($query);

		if ($rows > 0) {
			die("Username taken!");
		} else {
			$user_input = mysql_query("INSERT INTO users (username, password, firstname, lastname, email) VALUES ('$username','$password','$firstname','$lastname','$email')");	
			echo("Succesfuly Registered!");
		}
	}
}

?>


<html>
	
	<head>
		<title>Register</title>
	</head>
	
	<body>
		<form action="register.php" method="post">
			First Name: <input type="text" name="firstname"><br/>
			Last Name: <input type="text" name="lastname" /><br/>
			Email: <input type="text" name="email" /><br/>
			Username: <input type="text" name="username" /><br/>
			Password: <input type="password" name="password"/><br/>
			<input type="submit" value="Register!"/>	
		</form>
	</body>
	
</html>

Viewing all articles
Browse latest Browse all 13200

Trending Articles