gpt4 book ai didi

php - 插入新信息查询

转载 作者:行者123 更新时间:2023-11-30 01:14:10 25 4
gpt4 key购买 nike

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

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 子元素

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

插入子查询(不工作)

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

感谢您的回答。

最佳答案

要更新配偶信息,您正在执行查询,但要插入 child 信息,您没有执行查询。

$sql="INSERT INTO family_child (family_child_type, .......) 之后添加以下行

mysql_query($sql);

关于php - 插入新信息查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19216898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com