---
title: "php - mysql move records from table to other table"  
description: "php - mysql move records from table to other table"  
author: "Hank Greenberg"  
published: 2013-07-09  
updated: 2013-07-09  
canonical: https://www.mindstick.com/forum/1274/php-mysql-move-records-from-table-to-other-table  
category: "php"  
tags: ["php"]  
reading_time: 1 minute  

---

# php - mysql move records from table to other table

Hi Mindstickians,\
I want to [insert](https://www.mindstick.com/blog/173/executing-insert-delete-or-update-query-in-sqlserver-using-ado-dot-net) a record from first [query](https://www.mindstick.com/blog/202/sub-query-in-sqlserver) i means the rows make then with seconds query to insert. can some one help me please\
**if ( isset($_GET['del']) ) {** **$id = $_GET['del'];** **$[result](https://www.mindstick.com/blog/12011/advantages-of-getting-result-oriented-seo-from-an-agency) = mysqli_query($con,"[SELECT](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) * FROM [products](https://www.mindstick.com/news/2358/apple-will-use-us-made-semiconductors-in-its-products-to-lessen-its-dependency-on-asia) WHERE id='$id'");** **while($row = mysqli_fetch_array($result))** **{** **echo $row['[username](https://www.mindstick.com/forum/12798/there-is-no-viewdata-item-of-type-ienumerable-selectlistitem-that-has-the-key-username)'] . " " . $row['size'];** **echo "<br>";** **}** **$sql_move = mysqli_query($con,"INSERT INTO [history](https://yourviews.mindstick.com/view/81373/indian-railways-create-history-with-it-s-shramik-special-trains) (username, serial, [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character), arrive,size)");** **$sql = mysqli_query($con,"[DELETE](https://www.mindstick.com/forum/33620/how-to-delete-record-from-list-in-mvc-using-ajax) FROM products WHERE id='$id'");** **echo "its [deleted](https://www.mindstick.com/forum/160487/how-to-remove-the-deleted-git-code-marker-in-scrollbar-in-visual-studio-2022)";****}****?>****\**Thanks in advance.

## Replies

### Reply by AVADHESH PATEL

Try as following!\
First of all, you're trying to access $row from outside the loop, where it doesn't exist. Put the insert/delete lines in the loop, and then proceed.\
Second, you're not inserting the values.\
**$sql_move = mysqli_query($con, "INSERT INTO history (username, serial, image, arrive,size) VALUES ('{$row['username']}', '{$row['serial']}', '{$row['image']}', '{$row['arrive']}', '{$row['size']}'");**


---

Original Source: https://www.mindstick.com/forum/1274/php-mysql-move-records-from-table-to-other-table

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
