我试图让我的文本框输入货币格式。我做到了,但是当我将值插入到我的数据库中时,值会发生变化。当我输入 10000 时,它会更改 10,000。(到目前为止一切顺利。)但是当我将该值插入数据库时,该值变为 10。我真的很困惑。
这是我的脚本。我用的是php,mysql,字段类型是float
<?php include('header.php'); ?>
<?php
if(isset($_POST['simpan']))
{
$nama = htmlentities(addslashes($_POST['nama']));
$sim_wajib = $_POST['sim_wajib'];
$sim_pokok = $_POST['sim_pokok'];
$sim_sukarela = $_POST['sim_sukarela'];
$sim_wpinjam = $_POST['sim_wpinjam'];
$shu = $_POST['shu'];
$total = $sim_wpinjam + $shu;
if($nama != '' && $sim_wajib != '' && $sim_pokok != '' && $sim_sukarela != '' && $sim_wpinjam != '' && $shu != '' )
{
$sql = "INSERT INTO simpanan_tbl";
$sql .= "(nama, sim_wajib, sim_pokok, sim_sukarela, sim_wajibpinjam, shu, jumlah)";
$sql .= "VALUES('$nama','$sim_wajib','$sim_pokok','$sim_sukarela','$sim_wpinjam','$shu','$total')";
$query = mysql_query($sql) or die(mysql_error());
echo '<script type="text/javascript">alert("Data telah masuk!");document.location="manage_simpanan.php";</script>';
}
else
{
echo '<script type="text/javascript">alert("Kolom tidak boleh ada yang kosong!");</script>';
}
}
?>
<div id="rounded_add">
<script type="text/javascript">
function numberFormat(nr)
{
//remove the existing
var regex = /,/g;
nr = nr.replace(regex,'');
//split it into 2 parts
var x = nr.split(',');
var p1 = x[0];
var p2 = x.length > 1 ? ',' + x[1] : '';
//match group of 3 numbers (0-9) and add ',' between them
regex = /(\d+)(\d{3})/;
while(regex.test(p1))
{
p1 = p1.replace(regex, '$1' + ',' + '$2');
}
//join the 2 parts and return the formatted number
return p1 + p2;
}
</script>
<form method="post" name="form1">
<table id="add_simpan" class="add">
<tr>
<td>No Anggota</td>
</tr>
<tr>
<td><input type="text" id="" name="" class="textbox"></td>
</tr>
<tr>
<td>Nama</td>
</tr>
<tr>
<td><input type="text" id="nama" name="nama" class="textbox_left"></td>
</tr>
<tr>
<td>Simpanan Wajib</td>
</tr>
<tr>
<td><input type="text" id="sim_wajib" name="sim_wajib" class="textbox"></td>
</tr>
<tr>
<td>Simpanan Pokok</td>
</tr>
<tr>
<td><input type="text" id="sim_pokok" name="sim_pokok" class="textbox"></td>
</tr>
<tr>
<td>Simpanan Suka Rela</td>
</tr>
<tr>
<td><input type="text" id="sim_sukarela" name="sim_sukarela" class="textbox"></td>
</tr>
<tr>
<td>Simpanan Wajib Pinjam</td>
</tr>
<tr>
<td><input type="text" id="sim_wpinjam" name="sim_wpinjam" class="textbox" onkeyup="this.value = numberFormat(this.value);"></td>
</tr>
<tr>
<td>SHU</td>
</tr>
<tr>
<td><input type="text" id="shu" name="shu" class="textbox" onkeyup="this.value = numberFormat(this.value);"></td>
</tr>
<tr>
<td><input type="submit" value="Simpan" id="simpan" name="simpan" class="button blues"></td>
</tr>
</table>
</form>
</div><!-- END OF ROUNDED_ADD -->
<?php include('footer.php'); ?>