2013-10-07 2 views
0

여기에서하려는 일은 배우자 필드에서 데이터를 업데이트 할 수 있습니다. 자식 필드에 , 데이터베이스에 저장할 새 자식을 삽입/추가하려고합니다. 하지만 삽입 쿼리가 작동하지 않습니다.새 정보를 입력하십시오.

HTML 배우자

<td colspan="2" class="title_all_u">Family Member 1 (Spouse)</td> 
    </tr> 
    <tr> 
     <td class="pk">Family Type</td> 
     <td width="50%" class="pk_2"><input name="spouse_type" type="text" class="textfield_word" id="spouse_type" value="<?php echo $spouse_type ?>" /></td> 
    </tr> 
    <tr> 
     <td class="pk">Name</td> 
     <td width="50%" class="pk_2"><input name="spouse_name" type="text" class="textfield_word" id="spouse_name" value="<?php echo $spouse_name ?>" /></td> 
    </tr> 
    <tr> 
     <td class="pk">Gender Key</td> 
     <td class="pk_2"><input type="radio" name="spouse_gender" id="spouse_gender" value="Male" <?php if ($spouse_gender=="Male"){ ?> checked <?php } ?>/> 
     Male &nbsp; 
     <input type="radio" name="spouse_gender" id="spouse_gender" value="Female" <?php if ($spouse_gender=="Female"){ ?> checked <?php } ?> /> 
     Female </td> 
    </tr> 
    <tr> 
     <td class="pk">Date of Birth</td> 
     <td class="pk_2"><input name="spouse_date_birth" type="text" class="tcal" id="spouse_date_birth" value="<?php echo date_create($spouse_date_birth)->format('d-m-Y');?>" readonly="readonly"/></td> 
    </tr> 
    <tr> 
     <td class="pk">Country of Birth</td> 
     <td class="pk_2"> 
     <?php 
     $query = "SELECT country_type FROM country"; 
     $result = mysql_query ($query); ?> 
     <select name="spouse_country_birth" > 
     <?php while($row = mysql_fetch_array($result)){ ?> 
     <option value="<?php echo $row['country_type']?>" <?php if ($spouse_country_birth == $row['country_type']){ ?> selected <?php } ?>> 
     <?php echo $row['country_type']?></option> 
     <?php }?> 
     </select> 
     </td> 
    </tr> 
    <tr> 
     <td class="pk">Nationality</td> 
     <td class="pk_2"> 
     <?php 
     $query = "SELECT nationality_type FROM nationality"; 
     $result = mysql_query ($query); ?> 
     <select name="spouse_nationality" > 
     <?php while($row = mysql_fetch_array($result)){ ?> 
     <option value="<?php echo $row['nationality_type']?>" <?php if ($spouse_nationality == $row['nationality_type']){ ?> selected <?php } ?>> 
     <?php echo $row['nationality_type']?></option> 
     <?php }?> 
     </select> 
     </td> 
    </tr> 
    <tr> 
     <td class="pk">IC Number</td> 
     <td width="50%" class="pk_2"><input name="spouse_ic_num" type="text" class="textfield_word" id="spouse_ic_num" value="<?php echo $spouse_ic_num ?>" /></td> 
    </tr> 
    <tr> 
     <td class="pk">Passport No.</td> 
     <td width="50%" class="pk_2"><input name="spouse_pass_num" type="text" class="textfield_word" id="spouse_pass_num" value="<?php echo $spouse_pass_num ?>" /></td> 
    </tr> 
    <tr> 
     <td class="pk">Spouse employed</td> 
     <td width="50%" class="pk_2"><input name="spouse_employed" type="text" class="textfield_word" id="spouse_employed" value="<?php echo $spouse_employed ?>" /></td> 
    </tr> 
    <tr> 
     <td class="pk">Job Title</td> 
     <td width="50%" class="pk_2"><input name="spouse_job_title" type="text" class="textfield_word" id="spouse_job_title" value="<?php echo $spouse_job_title ?>" /></td> 
    </tr> 
    <tr> 
     <td class="pk">Spouse employer</td> 
     <td width="50%" class="pk_2"><input name="spouse_employer" type="text" class="textfield_word" id="spouse_employer" value="<?php echo $spouse_employer ?>" /></td> 
    </tr> 

HTML 아이 (작업) 배우자 자녀에 대한

$spouse_type = $_POST['spouse_type']; 
$spouse_name = $_POST['spouse_name']; 
$spouse_gender = $_POST['spouse_gender']; 
$spouse_date_birth = $_POST['spouse_date_birth']; 
$spouse_country_birth = $_POST['spouse_country_birth']; 
$spouse_nationality = $_POST['spouse_nationality']; 
$spouse_ic_num = $_POST['spouse_ic_num']; 
$spouse_pass_num = $_POST['spouse_pass_num']; 
$spouse_employed = $_POST['spouse_employed']; 
$spouse_job_title = $_POST['spouse_job_title']; 
$spouse_employer = $_POST['spouse_employer']; 


mysql_query("UPDATE family_spouse SET spouse_type = '".mysql_real_escape_string($_POST["spouse_type"])."', spouse_name = '".mysql_real_escape_string($_POST["spouse_name"])."', spouse_gender = '".mysql_real_escape_string($_POST["spouse_gender"])."', spouse_date_birth = STR_TO_DATE('".mysql_real_escape_string($_POST["spouse_date_birth"])."','%d-%m-%Y'), spouse_country_birth = '".mysql_real_escape_string($_POST["spouse_country_birth"])."', spouse_nationality = '".mysql_real_escape_string($_POST["spouse_nationality"])."', spouse_ic_num = '".mysql_real_escape_string($_POST["spouse_ic_num"])."', spouse_pass_num = '".mysql_real_escape_string($_POST["spouse_pass_num"])."', spouse_employed = '".mysql_real_escape_string($_POST["spouse_employed"])."', spouse_job_title = '".mysql_real_escape_string($_POST["spouse_job_title"])."', spouse_employer = '".mysql_real_escape_string($_POST["spouse_employer"])."' WHERE LAS_login_id = '".mysql_real_escape_string($_POST["LAS_login_id"])."'"); 

삽입 쿼리 (작동하지 않는)에 대한

<td colspan="2" class="title_all_u">Family Member 2 (Child)</td> 
    </tr> 
    <tr> 
     <td width="50%" class="pk">Family Type</td> 
     <td width="50%" class="pk_2"><input name="family_child_type" type="text" class="textfield_word" id="family_child_type" value="" /></td> 
    </tr> 
    <tr> 
     <td class="pk">Name</td> 
     <td width="50%" class="pk_2"><input name="family_child_name" type="text" class="textfield_word" id="family_child_name" value="" /></td> 
    </tr> 
    <tr> 
     <td class="pk">Gender Key</td> 
     <td class="pk_2"> 
     <input type="radio" name="family_child_gender" id="family_child_gender" value="Male" <?php if ($family_child_gender=="Male"){ ?> checked <?php } ?>/> 
     Male &nbsp; 
     <input type="radio" name="family_child_gender" id="family_child_gender" value="Female" <?php if ($family_child_gender=="Female"){ ?> checked <?php } ?> /> 
     Female 
     </td> 
    </tr> 
    <tr> 
     <td class="pk">Date of Birth</td> 
     <td class="pk_2"><input name="family_child_date_birth" type="text" class="tcal" id="family_child_date_birth" value="<?php echo date_create("")->format('d-m-Y');?>" readonly="readonly"/></td> 
    </tr> 
    <tr> 
     <td class="pk">Country of Birth</td> 
     <td class="pk_2"> 
     <?php 
     $query = "SELECT country_type FROM country"; 
     $result = mysql_query ($query); ?> 
     <select name="family_child_country" > 
     <?php while($row = mysql_fetch_array($result)){ ?> 
     <option value="<?php echo $row['country_type']?>" <?php if ($family_child_country == $row['country_type']){ ?> selected <?php } ?>> 
     <?php echo $row['country_type']?></option> 
     <?php }?> 
     </select> 
     </td> 
    </tr> 
    <tr> 
     <td class="pk">Nationality</td> 
     <td class="pk_2"> 
     <?php 
     $query = "SELECT nationality_type FROM nationality"; 
     $result = mysql_query ($query); ?> 
     <select name="family_child_nationality" > 
     <?php while($row = mysql_fetch_array($result)){ ?> 
     <option value="<?php echo $row['nationality_type']?>" <?php if ($family_child_nationality == $row['nationality_type']){ ?> selected <?php } ?>> 
     <?php echo $row['nationality_type']?></option> 
     <?php }?> 
     </select> 
     </td> 
    </tr> 
    <tr> 
     <td class="pk">IC Number</td> 
     <td width="50%" class="pk_2"><input name="$family_child_ic_num" type="text" class="textfield_word" id="$family_child_ic_num" value="" /></td> 
    </tr> 
    <tr> 
     <td class="pk">Passport No.</td> 
     <td width="50%" class="pk_2"><input name="family_child_pass_num" type="text" class="textfield_word" id="family_child_pass_num" value="" /></td> 
    </tr> 
    <tr> 
     <td class="pk">Education/Training</td> 
     <td width="50%" class="pk_2"><input name="family_child_education" type="text" class="textfield_word" id="family_child_education" value="" /></td> 
    </tr> 
    <tr> 
     <td class="pk">Handicapped</td> 
     <td width="50%" class="pk_2"><input name="family_child_handicaped" type="text" class="textfield_word" id="family_child_handicaped" value="" /></td> 
    </tr> 
    <tr> 
     <td class="pk">Child Custody</td> 
     <td width="50%" class="pk_2"><input name="family_child_custody" type="text" class="textfield_word" id="family_child_custody" value="" /></td> 
    </tr> 
    <tr> 
     <td class="pk">Married</td> 
     <td class="pk_2"> 
     <input type="radio" name="family_child_married_status" id="family_child_married_status" value="Yes" <?php if ($family_child_married_status=="Yes"){ ?> checked <?php } ?>/> 
     Yes &nbsp; 
     <input type="radio" name="family_child_married_status" id="family_child_married_status" value="No" <?php if ($family_child_married_status=="No"){ ?> checked <?php } ?> /> 
     No </td> 
    </tr> 
    <tr> 
     <td class="pk">Employed</td> 
     <td width="50%" class="pk_2"><input name="family_child_employed" type="text" class="textfield_word" id="family_child_employed" value="" /></td> 
    </tr> 

업데이트 쿼리

$family_child_type = $_POST['family_child_type']; 
$family_child_name = $_POST['family_child_name']; 
$family_child_gender = $_POST['family_child_gender']; 
$family_child_date_birth = $_POST['family_child_date_birth']; 
$family_child_country = $_POST['family_child_country']; 
$family_child_nationality = $_POST['family_child_nationality']; 
$family_child_ic_num = $_POST['family_child_ic_num']; 
$family_child_pass_num = $_POST['family_child_pass_num']; 
$family_child_education = $_POST['family_child_education']; 
$family_child_handicaped = $_POST['family_child_handicaped']; 
$family_child_custody = $_POST['family_child_custody']; 
$family_child_married_status = $_POST['family_child_married_status']; 
$family_child_employed = $_POST['family_child_employed']; 



$sql="INSERT INTO family_child (family_child_type, family_child_name, family_child_gender, family_child_date_birth, family_child_country, family_child_nationality, family_child_ic_num, family_child_pass_num, family_child_education, family_child_handicaped, family_child_custody, family_child_married_status, family_child_employed) VALUES (family_child_type = '".mysql_real_escape_string($_POST["family_child_type"])."', family_child_name = '".mysql_real_escape_string($_POST["family_child_name"])."', family_child_gender = '".mysql_real_escape_string($_POST["family_child_gender"])."', family_child_date_birth = STR_TO_DATE('".mysql_real_escape_string($_POST["family_child_date_birth"])."','%d-%m-%Y'), family_child_country = '".mysql_real_escape_string($_POST["family_child_country"])."', family_child_nationality = '".mysql_real_escape_string($_POST["family_child_nationality"])."', family_child_ic_num = '".mysql_real_escape_string($_POST["family_child_ic_num"])."', family_child_pass_num = '".mysql_real_escape_string($_POST["family_child_pass_num"])."', family_child_education = '".mysql_real_escape_string($_POST["family_child_education"])."', family_child_handicaped = '".mysql_real_escape_string($_POST["family_child_handicaped"])."', family_child_custody = '".mysql_real_escape_string($_POST["family_child_custody"])."', family_child_married_status = '".mysql_real_escape_string($_POST["family_child_married_status"])."', family_child_employed = '".mysql_real_escape_string($_POST["family_child_employed"])."')"; 

답해 주셔서 감사합니다.

+2

추가 다음 줄 당신은 심지어'이 마지막 쿼리를 executing' 있습니까? 귀하의 코드에 그렇게 나타나지 않습니다. 그리고 반환 된 오류 메시지를 보는 마음? 그들은 많이 말합니다 –

+0

오류 메시지가 나타 납니까? – Casey

+0

* sidenote : * 더 이상 사용되지 않는'mysql_ * '함수 사용을 중단하십시오. 대신에 MySQLi 또는 PDO를 사용하십시오. – Raptor

답변

0

배우자 정보를 업데이트하려면 쿼리를 실행 중이지만 쿼리를 실행하지 않은 자식 정보를 삽입하십시오. $sql="INSERT INTO family_child (family_child_type, .......

mysql_query($sql); 
관련 문제