My code is below:
<?php
require("db.php");
if(isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email'])){
//prevent SQL injections
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
//get MD5 hash of password
$password = md5($_POST['password']);
//check to see if username exists
$sql = mysql_query("SELECT Username FROM Users WHERE Username = '".$username."'");
if(mysql_num_rows($sql)>0){
die ("Username taken. Please pick a different Username");
}
mysql_query("INSERT INTO Users (Username, Password, Email, UserType)
VALUES ('$username','$password','$email','3')")
or die (mysql_error());
echo "Account Created.";
}
?>
<html>
<form action="register.php" method="post">
Username: <input name="username" ID="username" type="text"/><br>
Password: <input name"password" id="password" type="password"/><br>
Email: <input name="email" id="email" type="text" /><br>
<input type = "submit" value = "Submit"/>
</form>
</html>
I'm unsure as to why my users aren't being created. I've tried researching for the last few hours, but I'm not sure why this is erroring... it looks right to me...
If anyone could be of any help, that would be great. Thanks.
EDIT:
<?php
session_start();
$host="<myDBHost>"; // Host name
$localusername="<myDBusername>";
$localpassword="<myDBpassword";
$database_name="<mydbName>";
mysql_connect("$host", "$localusername", "$localpassword")
or die("An error occured while establishing a connection to the DB.");
mysql_select_db($database_name);
md5()on passwords. you should use a salt and hashing algorithm. and .................... Please, don't usemysql_*functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.