Below is my script for import data to mysql:
foreach ($file_data as $row) {
$sku = $row[$_POST["sku"]];
$title = $row[$_POST["title"]];
$slug = $row[$_POST["title"]];
$product_type = "physical";
$description = $row[$_POST["description"]];
}
if(isset($sku))
{
$query = "
INSERT INTO products
(sku, slug, product_type)
VALUES ".implode(",", $sku).",".implode(",", $slug).",".implode(",", $product_type)."
";
$statement = $connect->prepare($query);
if($statement->execute())
{
echo 'Data Imported Successfully';
}
}
And now can anyone help me how to now load $title
and $description
to second table product_details
?
@update @Mehrwarz
foreach ($file_data as $row) {
$sku = $row[$_POST["sku"]];
$title = $row[$_POST["title"]];
$slug = $row[$_POST["slug"]];
$product_type = "physical";
$description = $row[$_POST["description"]];
if (isset($sku)) {
$statement = $connect->prepare("INSERT INTO products
(sku, slug, product_type)
VALUES '$sku','$slug','$product_type'");
$statement2 = $connect->prepare("INSERT INTO product_details
(title, description)
VALUES '$title','$description'");
if (!$statement->execute()) {
$error = 'None or part of the data was updated';
}
}
}
echo $error ?? 'Data Updated Successfully';
2
Answers
Maybe you can push any array
This may work for you.