我试图将表单html页面中的用户数据插入到我的数据库中,但没有插入任何内容。我没有收到任何mysqli连接错误,所以我想我已经连接到数据库,但我觉得没有任何东西被传递给它。请任何帮助都很棒!谢谢!这是register.php代码
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Register</title>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$user = $_POST[user];
$pwd = $_POST[pwd];
require 'mysqli_connect.php';
$query = "INSERT INTO users (user_name, pass, registration_date) VALUES ($user,$pwd, NOW())";
$r = mysqli_query($conn, $query);
echo $query;
if ($r) {
echo "<h1>Thank You</h1>";
}
}
?>
<form action="register.php" method="post">
<label for="user">User</label>
<input type="text" name="user">
<label for="pwd">Password</label>
<input type="text" name="pwd">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
这是我的mysqli_connet.php代码
<?php
DEFINE ('USER_NAME', 'dhaval');
DEFINE ('PASS', 'open94');
DEFINE ('HOST', 'localhost');
DEFINE ('DATABASE', 'register');
$conn = @ mysqli_connect(HOST, USER_NAME, PASS, DATABASE) OR die ('Could not connect to MySQL: ' . mysqli_connect_error());
mysqli_set_charset($conn, 'utf8');
?>