您好在此代码中显示错误:
[" 1062:重复录入''对于密钥' reg_no'"]
任何人都可以帮助我。添加名称为reg_no
的字段时,为什么会显示此错误重复条目。
如果执行查询,我想返回true。
PHP
<?php
mysql_connect("localhost","root","");
mysql_select_db("hms");
//$student_name = !empty($_POST['student_name']) ? $_POST['student_name'] : $_GET['student_name'];
//$roll_no = !empty($_POST['roll_no']) ? $_POST['roll_no'] : $_GET['roll_no'];
$relation=!empty($_POST['relation']) ? $_POST['relation'] : $_GET['relation'];
$initial_id=!empty($_POST['initial_id']) ? $_POST['initial_id'] : $_GET['initial_id'];
$reg_no=!empty($_POST['reg_no']) ? $_POST['reg_no'] : $_GET['reg_no'];
$pmc=!empty($_POST['pmc']) ? $_POST['pmc'] : $_GET['pmc'];
$pc=!empty($_POST['pc']) ? $_POST['pc'] : $_GET['pc'];
$dob=!empty($_POST['dob']) ? $_POST['dob'] : $_GET['dob'];
$first_name=!empty($_POST['first_name']) ? $_POST['first_name'] : $_GET['first_name'];
$middle_name=!empty($_POST['middle_name']) ? $_POST['middle_name'] : $_GET['middle_name'];
$last_name=!empty($_POST['last_name']) ? $_POST['last_name'] : $_GET['last_name'];
$gender=!empty($_POST['gender']) ? $_POST['gender'] : $_GET['gender'];
$age=!empty($_POST['student_name']) ? $_POST['student_name'] : $_GET['student_name'];
$fh=!empty($_POST['fh']) ? $_POST['fh'] : $_GET['fh'];
$photo=!empty($_POST['photo']) ? $_POST['photo'] : $_GET['photo'];
$religion_id=!empty($_POST['religion_id']) ? $_POST['religion_id'] : $_GET['religion_id'];
$caste_id=!empty($_POST['caste_id']) ? $_POST['caste_id'] : $_GET['caste_id'];
$address=!empty($_POST['address']) ? $_POST['address'] : $_GET['address'];
$phone_office=!empty($_POST['phone_office']) ? $_POST['phone_office'] : $_GET['phone_office'];
$pin=!empty($_POST['pin']) ? $_POST['pin'] : $_GET['pin'];
$phone_resi=!empty($_POST['phone_resi']) ? $_POST['phone_resi'] : $_GET['phone_resi'];
$email=!empty($_POST['email']) ? $_POST['email'] : $_GET['email'];
$mobile_no=!empty($_POST['mobile_no']) ? $_POST['mobile_no'] : $_GET['mobile_no'];
$pmode=!empty($_POST['pmode']) ? $_POST['pmode'] : $_GET['pmode'];
$id_proof=!empty($_POST['id_proof']) ? $_POST['id_proof'] : $_GET['id_proof'];
$name_of_kin=!empty($_POST['name_of_kin']) ? $_POST['name_of_kin'] : $_GET['name_of_kin'];
$blood_group=!empty($_POST['blood_group']) ? $_POST['blood_group'] : $_GET['blood_group'];
$query="INSERT INTO patient_registration(reg_no,patient_main_type_id, patient_type_id,initial_id,first_name,middle_name,last_name,fth_mth_name,religion_id,date_of_birth,caste_id,address,pin,email,id_proof,phone_office, phone_residence,mobile_no,name_of_kin,relationship,entry_date,entry_time,patient_photo,payment_mode)
VALUES('$reg_no','$pmc','$pc','$initial_id','$first_name','$middle_name','$last_name','$fh','$religion_id','$dob','$caste_id','$address','$pin','$email','$id_proof','$phone_office','$phone_resi','$mobile_no','$name_of_kin','','','$relation','$photo','$pmode')";
$json_output = array();
if (!mysql_query($query )) {
$json_output[] = mysql_errno() . ": ".mysql_error();
}else{
$json_output[] = true;
}
print(json_encode($json_output));
mysql_close();
?>
答案 0 :(得分:0)
如果您尝试添加已存在的记录(注册号),则可能是您将reg_no用作主键或唯一,但是显示该错误。
答案 1 :(得分:0)
在您的表reg_no
中primary key
。您正尝试向注册表添加注册号的重复条目。将reg_no
字段设为auto_increment
,并将reg_no
保留在insert
上。
新查询看起来像
INSERT INTO patient_registration(patient_main_type_id, patient_type_id,initial_id,first_name,middle_name,last_name,fth_mth_name,religion_id,date_of_birth,caste_id,address,pin,email,id_proof,phone_office, phone_residence,mobile_no,name_of_kin,relationship,entry_date,entry_time,patient_photo,payment_mode)
VALUES('$pmc','$pc','$initial_id','$first_name','$middle_name','$last_name','$fh','$religion_id','$dob','$caste_id','$address','$pin','$email','$id_proof','$phone_office','$phone_resi','$mobile_no','$name_of_kin','','','$relation','$photo','$pmode')";