Select your language
Problem: You need to copy a row from a MYSql database table into same table or another table of same database using PHP.
Solution: We will use MySQL query which can be run using PHP.
Formula:INSERT INTO items(col1, col2, ..., coln)SELECT col1, col2, ..., colnFROM itemsWHERE id =132PHP code here:<?php$servername = "localhost"; $username = "youruser"; $password = "yourpass"; $dbname = "DBname"; // Now make connection $conn = new mysqli($servername, $username, $password, $dbname); // Then test connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql ="INSERT INTO targetTable (`title`, `slogon`, `alias`, `price`, `lang`, `direction`, `catid`, `created_by`, `created`, `last_update`, `image`, `access`, `state`, `announcement`, `btnTxt`, `btnLink`, `btnTarget`, `requirements`, `features`, `overview`, `description`, `downloadable`) SELECT `title`, `slogon`, `alias`, `price`, `lang`, `direction`, `catid`, `created_by`, `created`, `last_update`, `image`, `access`, `state`, `announcement`, `btnTxt`, `btnLink`, `btnTarget`, `requirements`, `features`, `overview`, `description`, `downloadable` FROM sourceTable WHERE id = 1"; $result = $conn->query($sql); if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; }$conn->close();?>
That's all !