gpt4 book ai didi

php - 无法添加或更新子行,外键约束失败

转载 作者:行者123 更新时间:2023-11-29 23:16:09 25 4
gpt4 key购买 nike

我正在尝试更新帐户的账单,但出现此错误“无法添加或更新子行:外键约束失败”。我已经搜索了原因,大部分都指出这是因为插入了主表中不可用的值。但是,我在帐单注册表单中,使用包含主表中帐号的下拉框,但它仍然存在此错误。

表格

<div id="contact_form">


<form method="post" action="proses_daftar_bill.php" name="maklumat_bill" oninput= "JumlahBayaran.value = parseFloat(AmaunCaj.value) + parseFloat(AmaunTunggakan.value) + parseFloat(AmaunPenalti.value) + parseFloat(AmaunPelbagai.value) + parseFloat(CajPF.value) + parseFloat(GST.value)">



<table>
<tr>
<label for="NoAkaun">Nombor Akaun</label>
<?php
require ("dbase.php");
$sql = "SELECT NoAkaun FROM maklumatakaun";
$result = mysql_query($sql);
echo "<select name='NoAkaun' id='NoAkaun' class='input_field' required /><option></option>";
while($kod = mysql_fetch_array($result)){
echo "<option value=".$kod['NoAkaun'].">" .$kod['NoAkaun']."</OPTION>";
}
echo "</select>";

?>
</tr>

<tr>
<td><label for="BulanBil">Tarikh Bil:</label> </td>
<td><select class="required bill_caj" name="BulanBil" id="BulanBil" width="300px" required/>
<option value="">--Pilih Bulan--</option>
<option value="Januari">Januari</option>
<option value="Februari">Februari</option>
<option value="Mac">Mac</option>
<option value="April">April</option>
<option value="Mei">Mei</option>
<option value="Jun">Jun</option>
<option value="Julai">Julai</option>
<option value="Ogos">Ogos</option>
<option value="September">September</option>
<option value="Oktober">Oktober</option>
<option value="November">November</option>
<option value="Disember">Disember</option>
</select></td>

<label for="TahunBil"></label><td><input type="text" maxlength="4" size="4" id="TahunBil" name="TahunBil" class="required year_field" placeholder="Tahun" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" required/></td>
</tr>

<tr>
<td>
<div class="cleaner_h10"></div>
<div class="cleaner_h10"></div>
<div class="cleaner_h10"></div>
<div class="cleaner_h10"></div>
</td>
</tr>


<tr>
<td><label for="AmaunCaj">Amaun</label></td>
<td><input type="text" name="AmaunCaj" id="AmaunCaj" class="bill_caj" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" required></td>


<td><label for="AmaunTunggakan">Tunggakan</label></td>
<td><input type="text" name="AmaunTunggakan" id="AmaunTunggakan" class="bill_caj" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" required></td>
</tr>

<tr>
<td><label for="AmaunPenalti">Penalti</label></td>
<td><input type="text" name="AmaunPenalti" id="AmaunPenalti" class="bill_caj" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"required></td>


<td><label for="AmaunPelbagai">Pelbagai</label></td>
<td><input type="text" name="AmaunPelbagai" id="AmaunPelbagai" class="bill_caj" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"required></td>
</tr>

<tr>
<td><label for="GST">GST</label></td>
<td><input type="text" name="GST" id="GST" class="bill_caj" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"required></td>
</tr>



<tr>
<td><label for="checkbox_pf">PF<input type="checkbox" onclick="codename()" name="checkbox_pf" value="ON"></label></td>



<td><label for="BacaanPF">Bacaan PF:</label></td>
<td><input type="text" id="BacaanPF" name="BacaanPF" class="bill_caj" value="0" disabled onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"></td>
</tr>

<tr>
<td></td>
<td><label for="CajPF">Caj PF:</label></td>
<td><input type="text" id="CajPF" name="CajPF" class="bill_caj" value="0" disabled onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"></td>
</tr>




<tr>
<td><label for="JumlahBayaran">Jumlah Bayaran:</label></td>
<td><input id="JumlahBayaran" name="JumlahBayaran" class="bill_caj" for="AmaunCaj AmaunTunggakan" step="any" readonly></td>
<div class="cleaner_h10"></div>
</tr>






<tr>
<td><input type="submit" value="Daftar" id="submit" name="register-submit" class="submit_btn " /></td>
<td><input type="reset" value="Batal" id="reset" name="reset" class="submit_btn" /></td>
</tr>

</table>

</form>

sql

<?php
require("dbase.php");

if ($_POST) {

$TarikhData = isset($_POST['TarikhData']) ? $_POST['TarikhData'] : '';
$username = isset($_POST['username']) ? $_POST['username'] : '';
$NoAkaun = isset($_POST['NoAkaun']) ? $_POST['NoAkaun'] : '';
$BulanBil = isset($_POST['BulanBil']) ? $_POST['BulanBil'] : '';
$TahunBil = isset($_POST['TahunBil']) ? $_POST['TahunBil'] : '';
$AmaunCaj = isset($_POST['AmaunCaj']) ? $_POST['AmaunCaj'] : '';
$AmaunTunggakan = isset($_POST['AmaunTunggakan']) ? $_POST['AmaunTunggakan'] : '';
$AmaunPenalti = isset($_POST['AmaunPenalti']) ? $_POST['AmaunPenalti'] : '';
$AmaunPelbagai = isset($_POST['AmaunPelbagai']) ? $_POST['AmaunPelbagai'] : '';
$GST = isset($_POST['GST']) ? $_POST['GST'] : '';
$BacaanPF = isset($_POST['BacaanPF']) ? $_POST['BacaanPF'] : '';
$CajPF = isset($_POST['CajPF']) ? $_POST['CajPF'] : '';
$JumlahBayaran = isset($_POST['JumlahBayaran']) ? $_POST['JumlahBayaran'] : '';




$sql = mysql_query("INSERT INTO maklumatbilakaun VALUES ('', '$TarikhData' , '$username' , '$NoAkaun' , '$BulanBil' , '$TahunBil' ,'$AmaunCaj' ,'$AmaunTunggakan' ,'$AmaunPenalti' ,'$AmaunPelbagai' , '$GST' , '$BacaanPF' ,'$CajPF' ,'$JumlahBayaran')");
echo mysql_error();
}






?>

问题到底是什么?

最佳答案

如果不在插入语句中指定值的列,则很容易将值插入到错误的列中。

$sql = mysql_query("INSERT INTO 
maklumatbilakaun (TarikhData, username, NoAkaun, BulanBil, TahunBil, AmaunCaj, AmaunTunggakan, AmaunPenalti, AmaunPelbagai, GST, BacaanPF, CajPF, JumlahBayaran)
VALUES ('$TarikhData' , '$username' , '$NoAkaun' , '$BulanBil' , '$TahunBil' ,'$AmaunCaj' ,'$AmaunTunggakan' ,'$AmaunPenalti' ,'$AmaunPelbagai' , '$GST' , '$BacaanPF' ,'$CajPF' ,'$JumlahBayaran')");

您还需要提供DEFAULT到列而不是空值,或者在构建插入语句时省略列(我更喜欢后一种方法,尽管我不确定 php 中字符串连接的效率如何)。

关于php - 无法添加或更新子行,外键约束失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27791347/

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