I am posting a new row to the database but wanted to return the new auto incremented id in the response using medoo. This seems to be generating a new blank row and returning that id.
<?php
   // Independent configuration
  require 'medoo.php';
  $database = new medoo(array( 
  // required 
  'database_type' => 'mysql', 
  'database_name' => 'db', 
  'server' => 'server', 
  'username' => 'user', 
  'password' => 'pw' 
));
   $database->insert("properties", array(
"name" => $_POST['name'],
  "address" => $_POST['address'],
 "address2" => $_POST['address2'],
  "city" => $_POST['city'],
 "state" => $_POST['state'],
  "zip" => $_POST['zip'],
 "lat" => $_POST['lat'],
 "lng" => $_POST['lng'],
 "website" => $_POST['website']
));
$last_id = $database->insert("properties", array(
    "propertyId" => "propertyId"
));
$propertyId = array(propertyId => $last_id);
echo json_encode($propertyId);
?>
The insert() method returns the last insert ID.
$insertId = $database->insert("properties", array(
  // etc...
));
echo $insertId;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With