I wanna select some column from one table (oldDataTable
) and insert into another table (newDataTable
). Both are in the same database. I tried. If i choose only one column it works. But if i choose more than one column nothing happens.
oldDataTable has columns like
Name | Date | Voltage | Current | Power | RMS.
I just wanna select columns like Name| Date| Power
and insert it into newDataTable
. I am doing this when user submit a form button. Any help please.
<?php
if (isset($_POST['submit'])){
include ("DBconnect.php");
$conn= mysqli_connect( $dbhost, $dbuser, $dbpass, $db );
if ($conn->connect_error){
die("Connection failed: " . $conn->connect_error);
}
else{
$insertNEQuery= "INSERT INTO newDataTable (Name, Date, Power) SELECT (Name, Date, Power) FROM oldDataTable WHERE ID = '2' ";
//it should be a bunch of rows. I have data for every one minute.
mysqli_query($conn, $insertNEQuery);
echo " data updated!";
$conn->close();
}
} else
echo " please click submit button!";
?>
```
The parentheses is not required in the SELECT
, the following query will work.
INSERT INTO newDataTable (Name, Date, Power)
SELECT Name, Date, Power FROM oldDataTable WHERE ID = '2'
So your code will be:
$insertNEQuery= "INSERT INTO newDataTable (Name, Date, Power) SELECT Name, Date, Power FROM oldDataTable WHERE ID = '2' ";
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments