我的代码如下:
<?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>
我不确定为什么没有创建我的用户。在过去的几个小时里,我已经尝试过研究,但我不确定为什么会出错......它看起来对我来说......
如果有人可以提供任何帮助,那就太好了。谢谢。
编辑:
<?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);