ผมจะบันทึกเวลาลงฐานข้อมูลด้วย ทำยังไงครับ

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: ผมจะบันทึกเวลาลงฐานข้อมูลด้วย ทำยังไงครับ

ผมจะบันทึกเวลาลงฐานข้อมูลด้วย ทำยังไงครับ

โดย Yuttana Jampa » 12/05/2019 6:53 pm

โค้ด: เลือกทั้งหมด

<?
    if($_POST[ok]){
    $sqlcus="select max(id_buy) as id_buy from tb_buy";
    $rs_resultcus = $db->select_table(tb_buy)->execute($sqlcus);
    $rowcus=$rs_resultcus->fetch_assoc();

$postfix=0;

if(empty($rowcus[id_buy])){
  $postfix+=1;//ตัวท้าย +1
  $code="B"."-"."00001"; 
} else {
  $postfix=substr($rowcus[id_buy],3,5);
  $postfix+=1;
  $postfix=str_pad($postfix,5,"0",STR_PAD_LEFT);
  $code="B"."-".$postfix;
}
    $b_name=$_POST[b_name];
    $b_product=$_POST[b_product];
    $b_num=$_POST[b_num];
    $b_price=$_POST[b_price]; 
    $c_product=$_POST[c_product]; 

    $data = array(
    'id_buy'=>$code, //$stucode,
    'b_name'=>$b_name,
    'b_product'=>$b_product,
    'b_num'=>$b_num,
     'c_product'=>$c_product,
    'b_price'=>$b_price
  );
  // print_r($data);// ใช้สำหรับให้แสดงข้อมูลใน $data
   //exit(); //จบการทำงาน ก่อนที่จะบันทึกลงฐานข้อมูล

  if($db->insert('tb_buy', $data)->execute())
  {
      echo "<script>alert('บันทึกข้อมูลแล้ว')</script>";
      
      echo "<script>window.location='index.php'</script>";
    }else{
      echo "<script>alert('ไม่สามารถบันทึกข้อมูล')</script>";
    }
    //echo "<meta HTTP-EQUIV='Refresh' CONTENT='1; URL=?'>";
  
  
    }
?>
<div class="container">
<div class="col-md-8 offset-md-2">
  
  <div class="card text-success border-success mb-3">
      <div class="card-header"><h4>รับซื้อสินค้า</h4></div>
      <div class="card-body">
        <div class="row">
          <div class="col-md-12">
<form method="post" action="">
          

          <label>ชื่อลูกค้า</label>  
          <div class="form-row">
            <div class="form-group col">
            <input type="text" class="form-control" placeholder="ชื่อลูกค้า" name="b_name"> 
            </div>
          </div>
          <label>รหัสสินค้า</label>  
          <div class="form-row">
            <div class="form-group col">
            <input type="text" class="form-control" placeholder="รหัสสินค้า" name="c_product"> 
            </div>
          </div>
          <label>ชื่อสินค้า</label>  
          <div class="form-row">
            <div class="form-group col">
            <input type="text" class="form-control" placeholder="ชื่อสินค้า" name="b_product"> 
            </div>
          </div>
          <label>จำนวน</label>  
          <div class="form-row">
            <div class="form-group col">
            <input type="text" class="form-control" placeholder="จำนวน" name="b_num" > 
            </div>
          </div>

          <label>ราคา</label>  
          <div class="form-row">
            <div class="form-group col">
            <input type="text" class="form-control" placeholder="ราคา" name="b_price"> 
            </div>
          </div>
          <input type="submit" class="btn btn-success " name="ok" value="บันทึก">
          
</form>
          </div>
        </div>
        
        

      </div>
    </div>
</div>
</div>

ข้างบน