【发布时间】:2018-04-27 20:42:44
【问题描述】:
我是初学者,我正在努力学习 PHP 和 SQL。我已经编写了下面的代码,所以我可以将数据插入到我的数据库中,但我不明白为什么它不起作用。它加载了所有内容,但是当我单击“注册”按钮时,它什么也不做。有人可以帮我弄清楚吗?
<?php include 'config.php'; ?>
<?php
if(isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$query = "INSERT INTO users1(username,password) VALUES ('$username','$password')";
$result = mysqli_query($con,$query) or die ("problem inserting new product into database");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Sign Up</title>
<style>
button {
text-align:center;
color: gray;
}
</style>
</head>
<body>
<h2>Sign Up</h2>
<h3>Enter your data to register</h3>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="POST">
<label class="user-name">Username</label><input type="text" name="username" placeholder="Enter your username" autofocus required"><br><br>
<label class="pass-word"> Password: </label><input type="password" name="pass" class="info" placeholder="Enter your Password" required ><br><br>
<button class="lbutton" type="submit" value="Submit">Sign Up</button>
<p>Already registered? <a href="login2.php">Login</a></p>
</body>
</html>
【问题讨论】:
-
你的按钮需要
name="submit" -
如果您刚刚开始,现在是在养成坏习惯之前查找how to prevent SQL injection in PHP和password hashing的好时机;)
-
我一定会查的
-
附带说明,您的标签需要
for属性