This is a code that I found somewhere on this site. It has to do with registering an account through a MySQL database. I want to know how I can add a line of code into here that prevents the use of numbers and symbols (so just a-z and A-Z) in the user name box. Thanks in advance!
PHP Code:
<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
mysql_connect("localhost", "root", "");
mysql_select_db("DATABASE");
// sanitize the name to make sure nobody hacks you.
$u = mysql_real_escape_string(stripslashes($_POST["u"]));
// md5 hashes aren't vulnerable for SQL injections, so no worries there
$p = md5(stripslashes($_POST["p"]));
$e = mysql_real_escape_string(stripslashes($_POST["e"]));
mysql_query("INSERT INTO accounts (name, password, email) VALUES('$u', '$p', '$e')") or die
(mysql_error());
die("Thank you for registering.");
}
?>
<html>
<head>
<title>Register</title>
</head>
<body>
<form action="" method="POST">
<p>User name: <input type="text" name="u" maxlength="12" /></p>
<p>Password: <input type="password" name="p" /></p>
<p>Email: <input type="text" name="e" /></p>
<p><input type="submit" value="Register Now" /></p>
</form>
</body>
</html>