Search code examples
phpmysqlformsechounique-id

PHP SQL : How to display Unique ID to which data is saved just now?


Please read this question for clear understanding

PHP SQL : How to save data to multiple database from one html form OR how to copy data from one database to another database automatically

As form.php is saving data to 2 different database table. In both the database the SNo is the Unique Column and is auto incremented. Everytime SNo is incremented and data is saved in that row. For a single data, SNo remains same in both the database table.

When data is saved successfully, form.php echo

Successfully Saved

I want to echo the SNo to which form.php just saved the data from any one of the database as SNo is same in both the database, as a reference number.

The message should be like this

Successfully Saved. You Reference No is ?? //What should be the code at ??

What should be the code for this ?


Solution

  • You can use

        mysqli_insert_id($conn)
    

    to retrieve last auto generated id.

    echo "Successfully Saved. You Reference No is".mysqli_insert_id($conn);