I store date in product_edit.php form, here is part of the script:

product_edit.php

if (isset($_POST['save'])){
	 	 		 
			 
	$tgl_masuk = date("y-m-j");
		
	if (empty($_POST['id'])){
	$result = mysql_query("INSERT INTO produk(nama_produk, harga, deskripsi, tgl_masuk, gambar) VALUES('".$nama."','".$harga."','".$deskripsi."','".$tgl_masuk."','".$gambar."')");
			}
	else{
	$result = mysql_query("UPDATE produk SET nama_produk='".$nama_produk."', harga='".$harga."', deskripsi='".$deskripsi."', gambar='".$gambar."' WHERE id=".$_POST['id']);
	$result = mysql_query($sqlstr) or die(mysql_error());
		
	//Jika mode edit, maka tidak akan dikirimkan konfirmasi kepada subscriber
	//if (empty($_REQUEST['id']))	kirimEmail($idKategori, $judul, $news);
	$confirmation = ($result) ? "Data telah tersimpan." : "Gagal menyimpan data.";	
	}
}

?>

I post or preview it in product_preview.php

product_preview.php

<?php 
include ("includes/koneksi.php");
	
$i = 1;
$output = mysql_query("SELECT * FROM produk") or die(mysql_error());
while($data = mysql_fetch_array($output)){
?>

<tr>
   <td><?php echo $i."</br>";?>
   <td><?php echo $data['nama_produk']."</br>";?></td>
   <td><?php echo $data['harga']."</br>";?></td>
   <td><?php echo date('j-M-Y',$data['tgl_masuk'])."</br>";?></td>
	<td>
            <a href="./product_edit.php?id=<?php echo $data['id_produk'];?>&mode=edit">Edit</a>  
            <a href="./product_preview.php?id=<?php echo $data['id_produk'];?>&mode=delete">Delete</a>
             </td>            	
        </tr>    

	
<?php
$i++;	
}

?>

I have this error:

Notice: A non well formed numeric value encountered in C:\xampp\htdocs\Masterlink\cgoods\product_preview.php on line 104
1-Jan-1970

I can't figure out why it's incorrect. The date stored correctly in the database as year-month-date (y-m-j) but an error for product_preview.php.

Add strtotime(): date('j-M-Y',strtotime($data['tgl_masuk'])) bye :)

Thanks. it works!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.