将注册信息插入Mysql数据库时出现问题 [英] Problems with inserting registering information into a Mysql database

查看:134
本文介绍了将注册信息插入Mysql数据库时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在注册信息方面有点麻烦.
它应该转到名为"mon"的数据库和名为"user"的表.此表包含信息"id","name"和"pass""."id"基于自动增量系统,因此无需在注册页面中定义.

I'm having a bit of trouble with register information.
It's supposed to go to a database called "mon" and to a table called "user".This table contains the information "'id','name',and 'pass'".The 'id' is based off of an auto increment system,so doesn't need to be defined in the register page.

没有错误报告,只是重新加载了页面.但是,当使用phpMyAdmin访问表时,它表明未创建新行.我需要帮助,因为我对PHP还是陌生的,所以不要.我不知道其中的很多问题.

No errors are reported,just a reload of the page.But,when visiting the table using phpMyAdmin,it shows that a new row wasn't created.I need help on this because I am fairly new to PHP and don't know much of the kinks of it.

代码:
Pastebin,因为即使我隔开了代码,stackoverflow的代码也很奇怪.

register.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>";
    }
    ?>

对此有任何帮助,非常感谢您创建一个标记为登录的会话,并在会话打开的情况下重定向到索引页面.

Any help on this,the creation of a session that marks login,and the redirecting to the index page with the session on is very appreciated.

推荐答案

结合给出的其他答案,您在表和列周围使用了常规引号,这些引号是无效的标识符限定符.

In conjunction with the other answers given, you are using regular quotes around your table and columns, which are invalid identifier qualifiers.

("INSERT INTO 'user' ('name', 'pass')
              ^    ^  ^    ^  ^    ^

应该删除哪个

("INSERT INTO user (name, pass)

或使用类似于引号的对号,但实际上不是引号;那是两种完全不同的动物.

or using ticks which resemble a quote, but is in fact NOT a quote; those are two different animals altogether.

("INSERT INTO `user` (`name`, `pass`)

关于MySQL标识符限定符的参考:

Reference on identifier qualifiers for MySQL:

密码

我还注意到您可能以纯文本形式存储密码.不建议这样做.

I also noticed that you may be storing passwords in plain text. This is not recommended.

使用以下之一:

  • CRYPT_BLOWFISH
  • crypt()
  • bcrypt()
  • scrypt()
  • On OPENWALL
  • PBKDF2
  • PBKDF2 on PHP.net
  • PHP 5.5's password_hash() function.
  • Compatibility pack (if PHP < 5.5) https://github.com/ircmaxell/password_compat/

其他链接:

有关列长的重要旁注:

如果并且当您决定使用password_hash()或crypt时,请务必注意,如果当前密码列的长度小于60,则需要将其更改为该长度(或更大).手册建议长度为255.

If and when you do decide to use password_hash() or crypt, it is important to note that if your present password column's length is anything lower than 60, it will need to be changed to that (or higher). The manual suggests a length of 255.

您将需要更改列的长度,并以新的哈希值重新开始,以使其生效.否则,MySQL将静默失败.

You will need to ALTER your column's length and start over with a new hash in order for it to take effect. Otherwise, MySQL will fail silently.

这篇关于将注册信息插入Mysql数据库时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆