I’ve created a php mysql driven web site. I’ve specified a primary and foreign key. The gallery table has an id and the images table has an id. There can be one gallery to many images: gallery table has a primary key and images table has a foreign key— they’re joined. The script below adds data to the images table, but the images are supposed to linked to a specific gallery. I’m doing an insert join in the script below. I keep getting his error message: Insert value list does not match column list: 1136 Column count doesn’t match value count at row 1. Thank you in advance for the help.
Code:
<?php
require ("common.php");
$g_id = $_POST['g_id'];
$query = "
INSERT INTO images (
p_id,
p_name,
p_title,
p_desc,
g_id
)
SELECT gallery.g_id
FROM gallery
Inner JOIN images on images.g_id = gallery.g_id;
";
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute();
}
catch(PDOException $ex)
{
die("Oh, No something went wrong. Please contact your systems administrator... " . $ex->getMessage());
}
?>