I'm new to PDO and php. I want to move a row from one table to another with a link i send to the script below.
LINK The "id" is used as a primary key in the invtable, (see FROM invtable in the script below)
submit-ads-florida.php?id=01820007985
SCRIPT submit-ads-florida.php
<?php
$host = "localhost";
$user = "user";
$password = "pass";
$database_name = "db";
$pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
$barCode = $GET['id'];
$query = "INSERT INTO adstable (Brand, Description, Price, Size, Price, Barcode)
SELECT Brand, Description, Price, Size, Price, Barcode FROM invtable
WHERE Barcode='".$barCode."'";
$pdo->query($query);
?>
PROBLEM
removed extra bracket by GET[id]). I'm getting the following error.
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1110 Column 'Price' specified twice' in /home/myaccount/public_html/florida-ave/submit-ads-florida.php:16 Stack trace: #0 /home/myaccount/public_html/florida-ave/submit-ads-florida.php(16): PDO->query('INSERT INTO flo...') #1 {main} thrown in /home/myaccount/public_html/florida-ave/submit-ads-florida.php on line 16
UPDATE
I corrected multiple entries of Price. No data is being add to adstable and I'm not getting any errors.
See Question&Answers more detail:os