【问题标题】:Zend db insertion exceptionZend db 插入异常
【发布时间】:2012-01-12 10:31:22
【问题描述】:

请一些人帮我验证了很多次,但我找不到我做错的地方

SQLSTATE[23000]: 完整性约束违规: 1062 Duplicate entry '' for key 'Index_6'

这是我的代码:

$first_name = $_POST ['firstName'];
$middle_name = $_POST ['middleName'];
$last_name = $_POST ['lastName'];
$office_ph_no = $_POST ['officePhoneNumber'];
$cell_ph_no = $_POST ['cellPhoneNumber'];
$email = $_POST ['emailId'];
$supervisor_name = $_POST ['supervisorName'];
$supervisor_email = $_POST ['supervisorEmail'];
$supervisor_ph = $_POST ['supervisorPhone'];
$pass = $_POST ['password'];

$sql = $db->query ( "INSERT INTO user( user_id, title, first_name, last_name, user_identity_id, email_id, password, office_phone_number, public_id, session_id, address_id, created_by, last_modified_by, created_on, last_modified_on, is_activated, is_deprecated, middle_name, cell_phone_number, superviser_name, superviser_email, superviser_phone_number) 

VALUES ( :p_user_id, :p_title, :p_first_name, :p_last_name, :p_user_identity_id, :p_email_id, :p_password, :p_office_phone_number, :p_public_id, :p_session_id, :p_address_id, :p_created_by, :p_last_modified_by, :p_created_on, :p_last_modified_on, :p_is_activated, :p_is_deprecated, :p_middle_name, :p_cell_phone_number, :p_superviser_name, :p_superviser_email, :p_superviser_phone )",

   array (
'p_user_id' => '',
'p_title' => NULL,
'p_first_name' => $first_name,
'p_last_name' => $last_name,
'p_user_identity_id' => 'id',
'p_email_id' => $email,
'p_password' => $pass,
'p_office_phone_number' => $office_ph_no,
'p_public_id' => NULL,
'p_session_id' => NULL,
'p_address_id' => NULL,
'p_created_by' => NULL,
'p_last_modified_by' => NULL,
'p_created_on' => '',
'p_last_modified_on' => '',
'p_is_activated' => '0',
'p_is_deprecated' => '0',
'p_middle_name' => $middle_name,
'p_cell_phone_number' => $cell_ph_no,
'p_superviser_name' => $supervisor_name,
'p_superviser_email' => $supervisor_email,
'p_superviser_phone' => $supervisor_ph 
)

【问题讨论】:

  • 哪一列有约束?是您尝试放置 NULL 值的某些列,还是您尝试使用 $_POST 中的值填充的列?

标签: php zend-db


【解决方案1】:

在数组中,名称“p_ is_deprecated”有一个空格。

【讨论】:

  • 感谢您在更改后发现我正在违反完整性约束:1062 Duplicate entry '' for key 'Index_6' 这个错误
  • 在你的数据库中,这个主键(Index_6)已经被另一个主管(我假设是主管)使用验证它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-21
  • 1970-01-01
  • 2019-05-06
  • 2012-11-23
相关资源
最近更新 更多