简体   繁体   English

PHP mySQLi插入查询未插入最后一个值

[英]PHP mySQLi insert query not inserted last value

So I have this query: 所以我有这个问题:

    $query = $connection->prepare("INSERT INTO userdata(Username, Name, Department, Access, Password) VALUES ( ? , ? , ? , ? , ? )");
    $query->bind_param('sssdi', $accname, $name, $department, $access, $accpass);
    $query->execute();
    $query->close();

The variables are: 变量是:

    $accname = 'js1234';
    $name = 'Joe Smith';
    $department = 'New';
    $access = '0';
    $accpass = md5('joe1234');

The mySQL structure is: mySQL结构是:

    Column     Type         Null    Default
    ID     int(11)      No       
    Username   varchar(6)   Yes     NULL     
    Name       varchar(50)  Yes     NULL     
    Department varchar(15)  Yes     NULL     
    Access     int(11)  Yes     NULL     
    Password   varchar(32)  No       

But when I run the php code it only inserts the number 63 into the Password column of the database and not the full md5 hash. 但是当我运行php代码时,它只将数字63插入数据库的Password列而不是完整的md5哈希。 Everything else inserts fine. 其他一切都很好。 What am I missing in the php query? 我在php查询中缺少什么?

The problem is because you are trying to insert a string as an integer, you will need to insert your password hash as a string 问题是因为您尝试将字符串作为整数插入,您需要将密码哈希作为字符串插入

$query->bind_param('sssds', $accname, $name, $department, $access, $accpass);
                      //^ note the "s" here for string instead of "i" that you used

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM