0

I want to get the result of an insert query like this :

$query = "INSERT INTO articles (Title,Description) VALUES ('{$title}','{$description}')";
$result = mysqli_query($connection, $query);

When I insert this article , I want his ID to use it in an other table ! the $result gives a true or false !

learner
  • 11
  • 6

3 Answers3

1

You can get the ID of the inserted row by calling the function mysqli_insert_id() directly after your mysqli_query().

$query = "INSERT INTO articles (Title,Description) VALUES ('{$title}','{$description}')";
$result = mysqli_query($connection, $query);
$id = mysqli_insert_id($connection);
Maarkoize
  • 2,601
  • 2
  • 16
  • 34
0

use mysqli_insert_id ()

$insertId = mysqli_insert_id ( $connection );
Vitthal
  • 327
  • 1
  • 13
-1

Use this it return the value of your table fiele which is (peimary key) in this table

mysql_query("INSERT INTO mytable (product) values ('kossu')");
printf("Last inserted record has id %d\n", mysql_insert_id());
Hasibur
  • 205
  • 1
  • 10