【问题标题】:MySQL 'bind_param' statement doesn't seem to work - UserCake cutomizationMySQL 'bind_param' 语句似乎不起作用 - 使用 Cake 自定义
【发布时间】:2014-11-25 13:25:41
【问题描述】:

所以我正在使用 UserCake 开发一个项目。我已将字段添加到“用户”表中。到目前为止,一切都很好。我遇到的问题是注册时返回成功但是SQL语句没有将任何表单数据放入数据库。

到目前为止,我已经成功地添加了必要的字段,并且能够从这些字段中提取数据,但是,我无法将数据推送到数据库中。我感觉它与 bind_param 语句有关,但我不确定。这是我正在处理的:

EDIT 9/30 5pm >>> 此时唯一的问题是数据没有被放入表中。

$stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."users (
                password,
                email,
                activation_token,
                last_activation_request,
                lost_password_request,
                active,
                title,
                sign_up_stamp,
                last_sign_in_stamp,
                company,
                address_1,
                address_2,
                city,
                state,
                zip,
                paid,
                first_name,
                last_name
                )
                VALUES (
                ?,
                ?,
                ?,
                '".time()."',
                '0',
                ?,
                'New Member',
                '".time()."',
                '0',
                ?,
                ?,
                ?,
                ?,
                ?,
                ?,
                '0',
                ?,
                ?
                )");

            $stmt->bind_param("sssisssssiiss", $secure_pass, $this->clean_email, $this->activation_token, $this->user_active, $this->company, $this->address_1, $this->address_2, $this->city, $this->state, $this->zip, $this->first_name, $this->last_name);
            $stmt->execute();
            print_r($stmt);
            $inserted_id = $mysqli->insert_id;
            $stmt->close();

编辑 >>> 解决空数组问题

我这样称呼新用户: $user = new User($password, $email, $token, $activationRequest, $passwordRequest, $active, $title, $signUp, $signIn, $company, $address_1, $address_2, $city, $state, $zip , $paid, $first_name, $last_name);

编辑 >>> 表uc_users ( id int(11) 非空, password varchar(225) 非空,

emailvarchar(150) 非空,

activation_tokenvarchar(225) 非空,

last_activation_request int(11) 非空,

lost_password_request tinyint(1) 非空,

active tinyint(1) 非空,

titlevarchar(150) 非空,

sign_up_stamp int(11) 非空,

last_sign_in_stampint(11) 非空,

companyvarchar(50) 默认为空,

address_1varchar(50) 非空,

address_2varchar(50) 非空,

cityvarchar(50) 非空,

statevarchar(20) 非空,

zip int(5) 非空,

paid tinyint(1) 非空,

first_name varchar(50) 非空,

last_namevarchar(50) 非空

) ENGINE=InnoDB 默认字符集=utf8 AUTO_INCREMENT=3 ;

【问题讨论】:

  • 列“公司”不能为空,您的公司字段设置了吗?
  • 是的,我在每个列为“?”的变量中都有一个值
  • 但是$this -> company 是空的,我看错了,你能做var_dump($this) 看看公司变量的值吗?
  • 刚刚添加了 print_r($user)

标签: php mysql sql registration usercake


【解决方案1】:

您表上的字段Company 不允许NULL 值,但您发送它null,正如我在您的问题( print_r($this) 部分)中看到的那样。

所以你有两种方法可以解决这个问题,

  1. 如果您确实需要公司,请根据需要设置公司字段并在验证时(发送查询后)检查它,这样您就可以远离此类问题。
  2. 否则更改数据库中的 company 字段,并允许其为 NULL。

【讨论】:

  • 我明白,这不是必需的。但是,我正在输入公司名称。甚至 first_name、last_name 等也是空的。
  • 能否提供你的table的DDL?
  • 我不是 100% 肯定你所说的 DDL 是什么意思,但我使用的是 MySQL。这就是你要找的吗?
  • 我知道,我是说users表的create table查询
  • 好吧,我就是这么想的。我只是把它放在那里
猜你喜欢
  • 2013-09-13
  • 1970-01-01
  • 1970-01-01
  • 2018-10-03
  • 1970-01-01
  • 2022-01-08
  • 2021-10-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多