Php 为什么显示wpdb insert sql的错误? 我正在尝试使用两个表的简单代码(一个客户可能有一个或多个电话号码):

Php 为什么显示wpdb insert sql的错误? 我正在尝试使用两个表的简单代码(一个客户可能有一个或多个电话号码):,php,mysql,sql,wordpress,mysqli,Php,Mysql,Sql,Wordpress,Mysqli,然后尝试将id\u客户作为桌上电话的FK: $lastid = $wpdb->insert_id; $wpdb->insert('Phones',array('number' => $_POST['anumber'], 'id_customer' => $lastid )); 然后插入: $lastid = $wpdb->insert_id; $wpdb->insert('Phones',array(

然后尝试将id\u客户作为桌上电话的FK:

$lastid = $wpdb->insert_id;
 $wpdb->insert('Phones',array('number' => $_POST['anumber'],
                         'id_customer' => $lastid ));
然后插入:

$lastid = $wpdb->insert_id;
 $wpdb->insert('Phones',array('number' => $_POST['anumber'],
                         'id_customer' => $lastid ));
在DB中它可以工作,但我得到了这个错误:

$lastid = $wpdb->insert_id;
 $wpdb->insert('Phones',array('number' => $_POST['anumber'],
                         'id_customer' => $lastid ));
WordPress数据库错误:[]插入到电话中(
number
id\u客户
)值('8','63')


为什么我会犯这样的错误?我只想用一个外键链接两个表,因为我有“1对多”关系

Customer
- id_customer   // primary key, autoincrement
- mtrname  // a varchar
- test  // a varchar
- password // a varchar

Phones
- id_phone    // primary key, autoincrement
- number  // a varchar
- id_customer // foreign key reference to Customer

如果有人需要,我想分享解决方案:

我发现这个错误是因为我把这两个都写在了一起:

$wpdb->show_errors();
$wpdb->print_error();
当我只使用其中一个时,我不会得到任何错误(我仍然不知道背后的逻辑,但很好…)


感谢您的评论,并感谢“Suhas Bachhav”的提示。

我肯定(谢天谢地)不是PHP专家,但似乎您需要迭代数组并为数组中的每个项生成insert语句。或者是一个临时表。我在table Phone中只有两列(数字和id_customer:引用第一个表中的id_customer),我不知道如何进行连接:/I我使用了SET,它工作得很好,但在wordpress之外。。。使用wordpress它不起作用:/Yes,我想说的是,您可能需要为数组中的每条记录运行insert。请在配置中检查wodb是否没有显示错误。您是否尝试过
$wpdb->print_error()?您可以共享确切的表结构吗?