I want the ID automatically generated in auto_increment in the wpne_posts table to be saved to another table named wpne_postmeta
The INSERT code for the first action is:
mysqli_query($con, "SELECT * FROM wpne_posts");
$sql1 = "
INSERT INTO
'wpne_posts'(
'ID',
'post_author',
'post_date',
'post_date_gmt',
'post_content',
'post_title',
'post_excerpt',
'post_status',
'comment_status',
'ping_status',
'post_password',
'post_name',
'to_ping',
'pinged',
'post_modified',
'post_modified_gmt',
'post_content_filtered',
'post_parent',
'guid',
'menu_order',
'post_type',
'post_mime_type',
'comment_count'
)
VALUES
(
ID,
'$_post_author',
'$_post_date',
'$_post_date_gmt',
'$_post_content',
'$_post_title',
'$_post_excerpt',
'$_post_status',
'$_comment_status',
'$_ping_status',
'$_post_password',
'$_post_name',
'$_to_ping',
'$_pinged',
'$_post_modified',
'$_post_modified_gmt',
'$_post_content_filtered',
'$_post_parent',
'$_guide',
'$_menu_order',
'$_post_type',
'$_post_mime_type',
'$_comment_count'
)
";
Next, I want to send the automatically generated ID value in the wpne_posts table to the wpne_postmeta table in the post_id column, see:
mysqli_query($con, "SELECT * FROM wpne_postmeta");
$sql2 = "
INSERT INTO
'wpne_postmeta'('meta_id', 'post_id', 'meta_key', 'meta_value')
VALUES
(
meta_id,
'ID',
'$meta_key_guest_name',
'$meta_value_guest_name'
),
(
meta_id,
'ID)',
'$meta_key_timestamp',
'$meta_value_timestamp'
),
(
meta_id,
'ID',
'$meta_key_timeslot',
'$meta_value_timeslot'
),
(
meta_id,
'ID',
'$meta_key_cf_meta_value',
'$meta_value_cf_meta_value'
),
(
meta_id,
'ID',
'$_appointment_title',
''
),
(
meta_id,
'ID',
'$_appointment_guest_surname',
''
)
";
mysqli_query($con, $sql1) or die("Erro SQL 1");
mysqli_query($con, $sql2) or die("Erro SQL 2");
I tried to do with mysqli_insert_id () , but I get value 0. I would like to save the ID value of the wpne_posts table to a variable or any other solution.
I think I'm kind of a layperson, anyway I appreciate help.