1
I want the value of ID automatically generated in auto_increment in the table wpne_posts is saved in another table called wpne_postmeta
The INSERT code of 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'
)
";
Just below, I want to send the automatically generated ID value in the table wpne_posts for the wpne_postmeta table in the column post_id, 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 0. I would like to save the value of the wpne_posts table ID into a variable or any other solution.
I think I’m a bit of a layman, so I appreciate your help anyway.
you did
mysqli_insert_id($con)
?– Thiago Magalhães
You need to run this between the two queries. You need to change the order of your code operations. And why do you have these SELECT in the middle?
– bfavaretto
Why reverse? I think I’ve fried my brain trying it...
– Expl0it