我正在尝试使用以下代码将用户输入插入数据库。
mysql_query("INSERT INTO 'users' ('Email', 'Username', 'Password') VALUES ($email, $username, $password)");
没有错误,但数据库似乎永远不会插入代码。难道我做错了什么?
这是我的整个代码,HTML 和所有
<?php
DEFINE ('SERVER', 'localhost');
DEFINE ('PASSWORD', '');
DEFINE ('USER', 'root');
$email = $_POST['email'];
$username = $_POST['username'];
$password = SHA1($_POST['pass']);
if(isset('submitted')
{
if($email && $username && $password)
{
$to = 'email@example.com'
$subject = 'subject'
$body = 'there was an error connecting to the db, please check it.'
$dbconnect = @mysql_connect(SERVER, USER, PASSWORD) or die("NO WORK!");
$query = "USE practice"
mysql_query($query);
mysql_query("INSERT INTO users (Email, Username, Password)
VALUES ('$email', '$username', '$password')") or die(mysql_erorr());
}
}
?>
<html>
<form action = "" method = "post">
<label>Email Address</label>
<input type="text" name="email" /> <br />
<label>Desired Username</label>
<input type="text" name="username" /> <br />
<label>Password</label>
<input type="password" name="pass" /> <br />
<input type="submit" value="Register" />
<input type="hidden" name="submitted" value=1 />
</form>
</html>