0

With the code below, im trying to duplicate a product row with ajax in a webshops table, named termek.

If the last product is ID 90, and i copy this, the new product will be ID 91.

Sometimes, and i dont know why, the ID 90(what i copyed), loose the image, the thumb and big cell in the table, or it is renamed or i dont know what going on.

Is this code okay for copying, or whats wrong whit it?

<?php
include_once("../../files/connect.php");
if(!empty($_POST))
{
    $id = mysqli_real_escape_string($kapcs, $_POST['id']);
    $sql = 
    "
        INSERT INTO termek
        (
                termek_nev,
                termek_seo,
                termek_rovid,
                termek_hosszu,
                termek_thumb,
                termek_big,
                termek_seo_title,
                termek_seo_rovid,
                termek_seo_kw,
                termek_status,
                termek_view,
                termek_akcio,
                termek_normal_ar,
                termek_akcios_ar,
                termek_cikkszam,
                termek_egyseg,
                termek_fooldal,
                termek_kiemelt,
                termek_suly,
                termek_keszlet_db,
                termek_keszlet_warning,
                termek_min_order,
                termek_allapot,
                termek_gyarto,
                termek_jobb_arat_btn,
                termek_tipus,
                termek_szavak
        )
        SELECT

                termek_nev,
                termek_seo,
                termek_rovid,
                termek_hosszu,
                termek_thumb,
                termek_big,
                termek_seo_title,
                termek_seo_rovid,
                termek_seo_kw,
                termek_status,
                termek_view,
                termek_akcio,
                termek_normal_ar,
                termek_akcios_ar,
                termek_cikkszam,
                termek_egyseg,
                termek_fooldal,
                termek_kiemelt,
                termek_suly,
                termek_keszlet_db,
                termek_keszlet_warning,
                termek_min_order,
                termek_allapot,
                termek_gyarto,
                termek_jobb_arat_btn,
                termek_tipus,
                termek_szavak

        FROM termek WHERE termek_id = '$id'

    ";

    if(mysqli_query($kapcs, $sql))
    {
        echo (int)1;
    }
    else
    {
         echo mysqli_error($kapcs);
    }
}
?>
Takács Zoltán
  • 117
  • 3
  • 13
  • check out this question (and answers). I think it is baisically the same question and the top answer should also solve your problem http://stackoverflow.com/questions/4039748/in-mysql-can-i-copy-one-row-to-insert-into-the-same-table – flynorc Dec 31 '16 at 11:23
  • isnt this the same code? But i dont get any error. – Takács Zoltán Dec 31 '16 at 11:52
  • Now i know whats the problem. If i copy a product, everything is the same, the images to. If i change the image at the product that i copyed or the new one, it will delete this image, and upload the new one. What now whit my post? Should i delete it? – Takács Zoltán Dec 31 '16 at 13:13
  • 1
    I think you should write an answer to your question in this post, in case someone else with similar problem finds it and then you helped someone else in the future :) – flynorc Dec 31 '16 at 17:39

1 Answers1

0

To solve the problem, i uploaded a noimage.jpg to the products folder. When im editing the copied or the old product and changing its image, i dont delete the old image, if the thumb or big column == noimage.jpg.

Sorry for bad english.

Takács Zoltán
  • 117
  • 3
  • 13