0

Hy, i have code with php to update data in database mysql,
i don't have any error in my code and it succesded to update data,

but why the data in database is not change?
its same with data before update

please help me,

this is my update.php code :

<?php
include ("koneksi.php");
include ("cek_loginadmin.php");

/* penanganan form */
$Jenis          = $_POST['jenis'];
$Nama_peralatan = $_POST['nama'];
$Part_no        = $_POST['part_no'];
$Lokasi         = $_POST['lokasi'];
$Merk           = $_POST['merek'];
$Satuan         = $_POST['satuan'];
$Jumlah         = $_POST['jumlah'];
$Expired        = $_POST['tanggal'];
$Fungsi         = $_POST['fungsi'];
$Keterangan     = $_POST['keterangan'];
$nama_file      = $_POST['gambar'];

//input ke db
//menentukan letak direktori file
  $lokasi_file = $_FILES['gambar']['tmp_name'];
  $nama_file   = $_FILES['gambar']['name'];
  $direktori   ="images/$nama_file"; 


// Apabila tidak ada gambar yang di upload
if (empty($lokasi_file)){
$query = sprintf("UPDATE lab_batubara SET   jenis           = '$Jenis',
                                            Nama_peralatan  = '$Nama_peralatan',
                                            Part_No         = '$Part_no',
                                            Lokasi          = '$Lokasi',
                                            Merk            = '$Merk',
                                            Satuan          = '$Satuan',
                                            Jumlah          = '$Jumlah',
                                            Expired         = '$Expired',
                                            Fungsi          = '$Fungsi',
                                            Keterangan      = '$Keterangan'
                                            where id        = '$_POST[id]'");



$sql = mysql_query($query);
$pesan="";

if ($sql) {
echo "Data berhasil di simpan".mysql_error();
echo $sql;
echo "$_POST";
}
else{
echo "Data gagal disimpan ".mysql_error();

$pesan .= mysql_error();
}

//$response = array('pesan'=>$pesan, 'data'=>$_POST);
//echo json_encode($response);
exit;
}

// Apabila ada gambar yang diupload
else{ 
$move= move_uploaded_file($lokasi_file,"$direktori");
$query = sprintf("UPDATE lab_batubara SET   jenis           = '$Jenis',
                                            Nama_peralatan  = '$Nama_peralatan',
                                            Part_No         = '$Part_no',
                                            Lokasi          = '$Lokasi',
                                            Merk            = '$Merk',
                                            Satuan          = '$Satuan',
                                            Jumlah          = '$Jumlah',
                                            Expired         = '$Expired',
                                            Fungsi          = '$Fungsi',
                                            Keterangan      = '$Keterangan',
                                            Gambar          = '$nama_file'
                                            WHERE id        = '$id'");


$sql = mysql_query($query);

if ($sql) {
echo  "Data berhasil disimpan" .mysql_error();
}
else{
echo "Data gagal disimpan" .mysql_error();
}

//$response = array('pesan'=>$pesan, 'data'=>$_POST);
//echo json_encode($response);
exit;
}
?>

and this is my edit code :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php include "koneksi.php" ?>
<?php
include "cek_loginadmin.php";
?>
<head>
<title>Input data peralatan</title>


  <link href="../jquery-ui-1.8.16.custom/development-bundle/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css"/>
  <script src="../jquery-ui-1.8.16.custom/js/jquery-1.6.2.min.js"></script>
  <script type="text/javascript"> var jY = $.noConflict(true); </script>
  <script src="../jquery-ui-1.8.16.custom/js/jquery-ui-1.8.16.custom.min.js"></script>  


<!--script jqery form!-->
<!--
<script src="jquery-1.2.3.min.js"></script> 
<script type="text/javascript"> var jQ = $.noConflict(true); </script>
<script type="text/javascript">
jQ(document).ready(function() {

     jQ().ajaxStart(function() {
         jQ('#loading').show();
         jQ('#result').hide();
    }).ajaxStop(function() {
         jQ('#loading').hide();
         jQ('#result').fadeIn('slow');
    });

     jQ('#frm').submit(function() {
     var formData = new FormData($(this)[0]);
        jQ.ajax({
            type: 'POST',
            url: jQ(this).attr('action'),
            data: jQ(this).serialize(),
            success: function(data) {
                jQ('#result').html(data);
            }
        })
        return false;
    });
})
</script>
<!--Akhir dari jquery form!-->
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript"> var jX = $.noConflict(true); </script>
<script type="text/javascript" src="jquery.form.js"></script>
<script type="text/javascript"src="jquery.validate.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
//aktifkan ajax di form
var options = {
success : showResponse,
beforeSubmit: function(){
return $("#frm").valid();
},
resetForm : true,
clearForm : true,
dataType : 'json'
};
$('#frm').ajaxForm(options);

//validasi form dgn jquery validate
$('#frm').validate({
rules: {
jumlah : {
digits: true,
minlength:1,
maxlength:10
}
},
messages: {
nama: {
required: "Nama peralatan harus di isi",

digits: "Isikan dengan angka"
}
}
});
});
function showResponse(responseText, statusText) {
var data = responseText['data'];
var pesan = responseText['pesan'];
alert(pesan);
}
</script>


  <!---datepicker!-->
  <script>

  $(document).ready(function() {
$( "#tanggal" ).datepicker({ altFormat: 'yy-mm-dd' });
        $( "#tanggal" ).change(function() {
             $( "#tanggal" ).datepicker( "option", "dateFormat","yy-mm-dd" );
         });
    });
  </script>
<body style="font-size:60.5%;">  
<div id="datepicker"></div>
<!--akhir dari datepicker!-->

<!--CSS Form dan Validasi form !-->
<style type="text/css">
body, table, input, select, textarea { font: 11px/20px Verdana, sans-serif; }
h4 { font-size: 18px; }
input { padding: 3px; border: 1px solid #999; }
td { padding: 3px; }
#result { background-color: #F0FFED; border: 1px solid #215800; padding: 10px; width: 400px; margin-bottom: 20px; }
</style>

<style type="text/css">

.error {
font-size:small;
color:red;
}
</style>
<!--akhir CSS Form dan Validasi form !-->
<?php
$query = "select * from lab_batubara where id='".mysql_real_escape_string($_GET['id'])."'";  
$result = mysql_query($query);  
$hasil = mysql_fetch_array($result);  
?>  
<h4>Edit Data Peralatan</h4>
<div id="loading" style="display:none;"><img src="loading.gif" alt="loading..." /></div>
<div id="result" style="display:none;"></div>
<form action="update_bop.php" enctype="multipart/form-data" method="post" id="frm1">
    <table>

        <tr>

            <td><label for="nama" class="labelfrm">Nama Alat</label></td>
            <td>
                <input name="nama" id="nama"size="40" type="text" class="required" value="<? echo $hasil['Nama_peralatan']; ?>"/>
            </td>
        </tr>
        <tr>
            <td><label for="part_no" class="labelfrm">Part No</label></td>
            <td>
                <input name="part_no" id="part_no" size="40" type="text" value="<? echo $hasil['Part_No']; ?>" />
            </td>
        </tr>
            <tr>
            <td><label for="jenis" class="labelfrm">Jenis</label></td>
            <td>
            <select name="jenis">
            <?php
            $tampil=("SELECT * FROM jenis_aset");
            $query_hasil=mysql_query($tampil);
            while($r=mysql_fetch_object($query_hasil))
            {
            echo "<option value=$r->Id_jenis>$r->Jenis</option>";
            }
            ?>
            </select>
            </td>
        </tr>
        <tr>
            <td><label for="lokasi" class="labelfrm">Lokasi</label></td>
            <td>
                <input name="lokasi" id="lokasi" size="60" type="text" value="<? echo $hasil['Lokasi']; ?>"/>
            </td>
        </tr>
        <tr>
            <td><label for="label" class="labelfrm">Merek<label></td>
            <td>
                <input name="merek" id="merek" size="30" type="text" value="<? echo $hasil['merk']; ?>"/>
            </td>
        </tr>
        <tr>
            <td><label for="satuan" class="labelfrm">Satuan</label></td>
            <td>
                <input name="satuan" id="satuan" size="30" type="text" value="<? echo $hasil['Satuan']; ?>"/>
            </td>
        </tr>
        <tr>
            <td><label for="jumlah" class="labelfrm">Jumlah</td>
            <td>
                <input name="jumlah" id="jumlah" size="30" type="text" value="<? echo $hasil['Jumlah']; ?>" />
            </td>
        </tr>
        <tr>
            <td><label for="tanggal" class="labelfrm">Expired</label></td>
            <td>
                <input name="tanggal" id="tanggal" type="text" value="<? echo $hasil['Expired']; ?>" />
            </td>
        </tr>
        <tr>
            <td><label for="fungsi" class="labelfrm">Fungsi</label></td>
            <td>
                <textarea name="fungsi" id="fungsi" cols="40" rows="3"><? echo $hasil['Fungsi']; ?></textarea>
            </td>
        </tr>
        <tr>
            <td><label for="keterangan" class="labelfrm">keterangan</label></td>
            <td>
                <textarea name="keterangan" id="keterangan" cols="30" rows="2"><? echo $hasil['Keterangan']; ?></textarea>
            </td>
        </tr>
        <tr>
            <td><label for="gambar" class="labelfrm">Gambar</label></td>
            <td>
                <input type="file" name="gambar" id="gambar"><br> 
                <?php echo "<img src='images/$hasil[Gambar]' width=100>";?>
            </td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td>
                <label for="submit" class="labelfrm">&nbsp;</label>
                <input type="submit" name="edit" value="edit" id="edit"/>
                <input type="reset" value="Reset" />
            </td>
        </tr>
    </table>
</form>
</body>
</html>
3
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by cokerz_written
0

but why the data in database is not change? its same with data before update

That means your query has failed. See this thread on how to determine what the error is.

0

Thanks for your answer bro,
but i have solved that,

the problem is the id, its not read..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.