php - Create an unique ID number after submit form

admin2025-06-05  0

I'm still learning PHP and MySQL and need to create a unique number in Wordpress site (as a order number ID) every time, when user fill and submit "order" form from frontend and save it to database. Next submit will create a number+1. Website is not running on Woocommerce. No cart, checkout, products...

Thanks for help! :)

I'm still learning PHP and MySQL and need to create a unique number in Wordpress site (as a order number ID) every time, when user fill and submit "order" form from frontend and save it to database. Next submit will create a number+1. Website is not running on Woocommerce. No cart, checkout, products...

Thanks for help! :)

Share Improve this question edited Dec 30, 2018 at 11:05 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Dec 30, 2018 at 10:57 JurajJuraj 1542 silver badges11 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

in order to do this use

 AUTO_INCREMENT PRIMARY KEY 

while you define your table. Your table should be something like this:

CREATE TABLE `order` (
            `order_id` INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `user_group_id` INT(11) UNSIGNED NOT NULL,
            `status` BIT,
            `meta` VARCHAR ( 255 ),
            `value` TEXT,
            `update_time` TIMESTAMP
            )DEFAULT CHARSET = utf8;

remember that you could change other columns, the important one is order_id which is auto increment

You can get the unique ID number by using the merge tag {submission:sequence}. It allows you to get the submission number of the current user’s submission.It only populates after the submission data has been saved to the database.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749058508a316000.html

最新回复(0)