samedi 1 novembre 2014

query not executing and error in php


Vote count:

0




Hi in this code it showing ["1062: Duplicate entry '' for key 'reg_no'"] this error can any one please help me.why it showing this error duplicate entry where added the field with name reg_no. I want to return true if query executes.


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();
?>


asked 1 min ago

user

12






query not executing and error in php

Aucun commentaire:

Enregistrer un commentaire