Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- cut here -->
- <form name="input_data" id="input_data" action="insertpinjaman.php" method="post">
- <table border='0' border='#CC3366' cellpadding='3' cellspacing='0' style='border-collapse:collapse'>
- <tbody>
- <tr>
- <td>No.Pinjaman</td>
- <td><input type="text" name="id_pinjam" required value="<?php echo kdauto("pinjaman","P"); ?>" readonly /></td>
- </tr>
- <tr>
- <tr>
- <td>No.Nasabah</td>
- <td><select name="no_nasabah" required="required">
- <?php
- $no_nasabah= mysql_query("select no_nasabah from nasabah");
- while ($row = mysql_fetch_array($no_nasabah)){
- echo "<option value =$row[no_nasabah]>$row[no_nasabah]</option>";
- }
- ?>
- </select>
- </td>
- </tr>
- <tr>
- <td>Barang</td>
- <td>
- <select id="barang" name="barang" required="required">
- <?php
- $tipe= mysql_query("select tipe,hargataksir from nilaitaksir");
- $hargataksir=array();
- while ($row = mysql_fetch_array($tipe)){
- $hargataksir[]=array($row[tipe],$row[hargataksir]);
- echo "<option value='{$row[tipe]}'>{$row[tipe]}</option>\n";
- }
- ?>
- </select>
- </td>
- </tr>
- <tr>
- <td>Pinjaman</td>
- <td><input type="text" name="pinjaman" id="pinjaman" maxlength="100" required="required" /></td>
- </tr>
- <tr>
- <td>Tanggal</td>
- <td>
- <input type="date" name="tanggal" maxlength="100" required="required" value="<?php echo date('Y-m-d'); ?>" />
- </td>
- <tr>
- <td>Status</td>
- <td>
- <select name='status' required="required">
- <option value='Belum'>Belum</option>
- </select>
- </td>
- </tr>
- <tr>
- <td align="right">
- <input type="button" id="submit" name="submit" value="Simpan" onSubmit="javascript:cek_harga();"/>
- </td>
- <td>
- <input type="button" value="Batal" onClick="self.history.back()">
- </td>
- </tr>
- </tbody>
- </table>
- <script>
- <?php
- echo "var hargataksir=new Array();\n";
- foreach($hargataksir AS $data)
- {
- echo "hargataksir['".$data[0]."']=".str_replace('.','',$data[1]).";\n";
- }
- ?>
- $(document).ready(function(){
- $('#submit').click(function(){
- if(parseFloat(hargataksir[$('#barang').val()])>=parseFloat($('#pinjaman').val()))
- {
- $('#input_data').submit();
- }
- else
- {
- alert('terlalu besar');
- }
- });
- });
- </script>
- <?php
- //-- CATATAN
- * form ditambah attribute 'id="input_data"'
- * input type="submit" diganti input type="button" dan ditambah attribute 'id="submit"'
- ?>
- //--untuk sisi server-nya bisa dibuat:
- <?php
- //panggil file config.php untuk menghubung ke server
- include('conn-db.php');
- //tangkap data dari form
- $harga_taksir = $_POST['harga_taksir'];
- $id_pinjam = $_POST['id_pinjam'];
- $no_nasabah = $_POST['no_nasabah'];
- $barang = $_POST['barang'];
- $pinjaman = $_POST['pinjaman'];
- $tanggal = $_POST['tanggal'];
- $status = $_POST['status'];
- $jatuh_tempo = date('Y-m-d',strtotime('+30 day',strtotime($tanggal)));
- $sql="IF NOT EXIST(SELECT 1 FROM nilaitaksir WHERE hargataksir<$pinjaman AND tipe='$barang')
- INSERT INTO pinjaman
- (id_pinjam, barang, no_nasabah, tanggal, tanggal_perpanjang, pinjaman, status, jatuh_tempo)
- VALUES
- ('$id_pinjam', '$barang', '$no_nasabah', '$tanggal', '$tanggal', '$pinjaman', '$status', '$jatuh_tempo')"
- $query = mysql_query($sql) or die(mysql_error());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement