Skip to content

Instantly share code, notes, and snippets.

@malikkurosaki
Created January 30, 2018 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malikkurosaki/8e483843e79b6c0d86cf5cb2644c4cb7 to your computer and use it in GitHub Desktop.
Save malikkurosaki/8e483843e79b6c0d86cf5cb2644c4cb7 to your computer and use it in GitHub Desktop.
this example code for get last id in db
<?php
$host = "127.0.0.1:3306";
$user = "root";
$pass = "";
$db = "malikdata";
$line = new mysqli($host,$user,$pass,$db);
if($line->connect_error){
echo "<br>connection error".$line->connect_error;
}else{
echo "connection succsesfuly<br>";
}
$sql = "INSERT INTO halaman(judul,content)VALUES('halaman tiga','ini content halaman dua agak panjang tapi tidak mengapa lah bisa dibaca yang penting soalnya masih baru nyoba gitu')";
if($line->query($sql) === TRUE){
$last_id = $line->insert_id;
echo "berhasil memasukkan data<br>".$last_id;
}else{
echo "error".$sql."koneksi".$line->error;
}
$line->close();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment