插入查询以获取新信息

时间:2013-10-07 04:07:44

标签: php html mysql wamp

我在这里尝试做的是,在配偶领域,我可以更新数据,并且它可以工作。 在子场,我试图插入/添加将存储在数据库中的新子。 但我的插入查询不起作用。

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 child

<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>

更新配偶(工作)的查询

$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"])."'");

为Child插入查询(不工作)

$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"])."')"; 

感谢您的回答。

1 个答案:

答案 0 :(得分:0)

要更新您正在执行查询的配偶信息,但要插入未执行查询的子信息。

$sql="INSERT INTO family_child (family_child_type, .......

之后添加以下行
mysql_query($sql);