Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

PHP 7 MySQL Database Script to Copy & Transfer Data From One Table to Another in Browser

Posted on January 16, 2023

 

 

Welcome folks today in this blog post we will be using php to copy and transfer data from one mysql table to another in browser. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to download the xammp control panel and start the apache server and mysql database as shown below

 

 

 

 

And after that we need to create the database and inside it we will be creating a sample user table and insert some data as shown below

 

 

 

 

 

 

 

 

 

And now we need to create the userclone table inside which we will transfer or copy all this above data as shown below. The structure needs to be the same in terms of columns

 

 

 

 

And now make an index.php script and copy paste the below code

 

 

index.php

 

 

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
 
$host="localhost";
$username="root";
$password="";
$db="dbsample";
 
$connection= new mysqli($host,$username,$password,$db);
 
if($connection === false){
    die("Not connected to database");
}
 
?>

 

 

As you can see we are first of all connecting to mysql database using the host,username,password and dbname and then we are using the mysqli constructor to connect and we pass these 4 things to connect to database.

 

 

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
 
$host="localhost";
$username="root";
$password="";
$db="dbsample";
 
$connection= new mysqli($host,$username,$password,$db);
 
if($connection === false){
    die("Not connected to database");
}
 
$sql_query = "INSERT userclone select * FROM user";
 
if($connection->query($sql_query) === true){
    echo "data copied successfully";
}
else{
    echo "some error occured";
}
 
?>

 

 

As you can see we are using the INSERT statement to copy all the data and the rows from the user table to the userclone table and we are displaying the success messages if the query is successful.

 

Recent Posts

  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Android Java Project to Make HTTP Call to JSONPlaceholder API and Display Data in RecyclerView Using GSON & Volley Library
  • Android Java Project to Download Youtube Video Thumbnail From URL & Save it inside SD Card
  • Android Java Project to Embed Google Maps & Add Markers Using Maps SDK
  • Android Java Project to Download Random Image From Unsplash Using OkHttp & Picasso Library & Display it
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme