How to get the next id in mysql to insert it in the table ?
INSERT INTO payments (date, item, method, payment_code) VALUES (NOW(), '1 Month', 'paypal', CONCAT("chaminda", id))
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.Sign up to join this community
Here is an approach for this.
Step 1: Insert without payment_code. Step 2: Get mysql_insert_id from STEP 1. Step 3: Update payment_code with where condition as mysql_insert_id.
Code Snippet in Php: The commands might have to be corrected.
1. mysql_query("INSERT INTO payments (date, item, method, payment_code) VALUES (NOW(), '1 Month', 'paypal')"); 2. printf("Last inserted record has id %d\n", mysql_insert_id()); 3. mysql_query(“UPDATE payments set payment_code=CONCAT("chaminda",mysql_insert_id()) where id=mysql_insert_id());