我在注册信息方面遇到了一些问题。
它应该转到一个名为“mon”的数据库和一个名为“user”的表。该表包含信息“'id','name'和'pass'”。'id'基于自动增量系统,因此不需要在寄存器页面中定义。
没有报告错误,只是重新加载页面。但是,当使用 phpMyAdmin 访问表时,它显示未创建新行。我需要这方面的帮助,因为我对 PHP 相当陌生,不知道我不太了解其中的奥秘。
代码:
Pastebin because stackoverflow is acting weird with my code even though I spaced it.
注册.php:
<?php
require_once 'connect.php';
if(!empty($_POST)) {
if(isset($_POST['username'], $_POST['password'], $_POST['desc'])) {
$username = $_POST['username'];
$password = $_POST['password'];
if(!empty($username) && !empty($password)) {
$insert = $db->prepare("INSERT INTO 'user' ('name', 'pass') VALUES (?, ?)");
$insert->bind_param('ss', $username, $password);
}
}
}
?>
<html>
<head>
<?php
require_once 'style.php';
?>
<title>si | Registering an Account</title>
</head>
<body>
<?php
require_once 'header.php';
?>
<div id="page">
<h2>Register an Account on Si</h2>
<form action="" method="post">
<input type="text" name="username" placeholder="Username" autocomplete="off">
<input type="password" name="password" placeholder="Password" autocomplete="off">
<button>Register</button>
</form>
</div>
</body>
</html>
connect.php:
<?php
$db = new mysqli('127.0.0.1', 'root', '');
if($db->connect_errno) {
echo "<p id='gotem'>Something has gone wrong.Tell J to fix it.</p>";
}
?>
对此的任何帮助,创建标记登录的 session ,以及在 session 打开时重定向到索引页面,我们都非常感激。
最佳答案
结合给出的其他答案,您在表格和列中使用了常规引号,这是无效的标识符限定符。
("INSERT INTO 'user' ('name', 'pass')
^ ^ ^ ^ ^ ^
应该删除哪个
("INSERT INTO user (name, pass)
或使用类似于报价的刻度,但实际上不是报价;这是两种不同的动物。
("INSERT INTO `user` (`name`, `pass`)
MySQL 标识符限定符引用:
密码
我还注意到您可能以纯文本形式存储密码。不建议这样做。
使用以下其中一项:
- CRYPT_BLOWFISH
-
crypt()
-
bcrypt()
-
scrypt()
- On OPENWALL
- PBKDF2
- PBKDF2 on PHP.net
- PHP 5.5
password_hash()
功能。 - 兼容包(如果 PHP < 5.5)https://github.com/ircmaxell/password_compat/
其他链接:
关于列长度的重要旁注:
如果您决定使用 password_hash()
或 crypt,请务必注意,如果您当前的密码列的长度小于 60,则需要将其更改为该值(或更高)。手册建议长度为255。
您需要更改列的长度并使用新的哈希值重新开始才能生效。否则,MySQL 将默默地失败。
关于php - 将注册信息插入Mysql数据库时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35111358/