-4
<section class="content">
<div class="row">
<div class="col-md-12">
<div class="box box-primary">
<!-- form start -->
<form role="form" class="form-horizontal" action="modules/medicines_transaction/proses.php?act=insert" method="POST" name="formObatMasuk">
<div class="box-body">
<?php
$query_id = mysqli_query($mysqli, "SELECT RIGHT(codigo_transaccion,7) as codigo FROM transaccion_medicamentos
ORDER BY codigo_transaccion DESC LIMIT 1")
or die('Error : '.mysqli_error($mysqli));
$count = mysqli_num_rows($query_id);
//mysql_query('INSERT INTO ...');
//if (mysql_errno() == 1062) {
// print 'no way!';}
if ($count <> 0) {
$data_id = mysqli_fetch_assoc($query_id);
$codigo = $data_id['codigo']+1;
} else {
$codigo = 1;
}
$tahun = date("Y");
$buat_id = str_pad($codigo, 7, "0", STR_PAD_LEFT);
$codigo_transaccion = "ES-$tahun-$buat_id";
?>
<div class="form-group">
<label class="col-sm-2 control-label">Codigo da Operação </label>
<div class="col-sm-5">
<input type="text" class="form-control" name="codigo_transaccion" value="<?php echo $codigo_transaccion; ?>" readonly required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Data</label>
<div class="col-sm-5">
<input type="text" class="form-control" data-date-format="dd-mm-yyyy" name="fecha_a" autocomplete="off" value="<?php echo date("d-m-Y"); ?>" readonly required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Hora</label>
<div class="col-sm-5">
<input type="text" class="form-control" name="created_date" autocomplete="off" value="<?php echo date("H:i"); ?>" readonly required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Data de Expiração</label>
<div class="col-sm-5">
<input type="text" class="form-control date-picker" data-date-format="dd-mm-yyyy" name="expdata" autocomplete="off" >
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Fornecedor</label>
<div class="col-sm-5">
<select class="chosen-select" name="origem_destino" data-placeholder="Selecione um Fornecedor" autocomplete="off" >
<option value=""></option>
<option value="Dep.C.Filhos">Dep.C.Filhos</option>
<option value="Farwell">Farwell</option>
<option value="ElnorFarma">ElnorFarma</option>
<option value="O.Kussonga">O.Kussonga</option>
<option value="UnicaFarma">UnicaFarma</option>
<option value="NCR">NCR</option>
<option value="D.P.S.M.L">D.P.S.M.L</option>
</select>
</div>
</div>
<hr>
<div class="form-group">
<label class="col-sm-2 control-label">Produto</label>
<div class="col-sm-5">
<select class="chosen-select" name="codigo" data-placeholder=" Seleccione um Producto " onchange="tampil_obat(this)&limpa()" autocomplete="off" required>
<option value=""></option>
<?php
$query_obat = mysqli_query($mysqli, "SELECT codigo, produto FROM Medicamentos ORDER BY produto ASC")
or die('error '.mysqli_error($mysqli));
while ($data_obat = mysqli_fetch_assoc($query_obat)) {
echo"<option value=\"$data_obat[codigo]\"> $data_obat[codigo] | $data_obat[produto] </option>";
}
?>
</select>
</div>
</div>
<span id='stok'>
<div class="form-group">
<label class="col-sm-2 control-label">Stock</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="stok" name="stock" readonly required>
</div>
</div>
</span>
<div class="form-group">
<label class="col-sm-2 control-label">Quantidade</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="jumlah_masuk" placeholder="0" name="num" autocomplete="off" onKeyPress="return goodchars(event,'0123456789',this)" onkeyup="hitung_total_stok(this)&cek_jumlah_masuk(this)" maxlength="5" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Operação</label>
<div class="col-sm-5">
<select name="transaccion" id="transaccion" required class='form-control' onchange="hitung_total_stok();">
<option value="Entrada">Entrada</option>
<option value="Saida">Saida</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Total Stock</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="total_stok" name="total_stock" readonly required>
</div>
</div>
</div><!-- /.box body -->
<div class="box-footer">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-primary btn-submit" name="Guardar" value="Guardar">
<a href="?module=medicines_transaction" class="btn btn-default btn-reset">Cancelar</a>
</div>
</div>
Sets the column as
autoincrement
and passesnull
in theinsert
– Costamilam
When you say: - without giving duplicate key error means that: 1) duplicate key must be inserted anyway; 2) duplicate key must not be inserted; 3) duplicate key must be renamed and entered; or 4) ignore duplicate keys ?
– LipESprY
– Eliarth Ramos
William main column is varchar, does not accept auto_increment
– Eliarth Ramos