Copy row to new row in MySQLi database using PHP

January 24, 2024


$query = "
INSERT INTO items (
item_id, 
title, 
price
)

SELECT 
id, 
title, 
price

FROM items
WHERE deleted != 'y'
AND id = ?
LIMIT 1
";

$stmt = $mysqli -> prepare($query);
$stmt -> bind_param("s", $item_id);
$stmt -> execute();

$insert_id = $mysqli -> insert_id;

if ( $insert_id > 0 ) {

echo $insert_id;

}


Comments

There are no comments.


Comment on this Article

Your email address will never be published. Comments are usually approved within an hour or two. (to prevent spam)