Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2006
    Posts
    116
    Plugin Contributions
    0

    Default insert not working

    i have my products in a text file that i am trying to upload on to zen cart using php. i have thebelow line of cide to add to products_description table. data is an array that ontains the info i wnt to add. i am new tophp so forgive the stupid error i might be making.


    $request1 = "INSERT INTO products_description (products_id, language_id, products_name) VALUES (200,1,$data[1])";
    mysql_query($request1) or Die('didnot work');

  2. #2
    Join Date
    Feb 2006
    Posts
    116
    Plugin Contributions
    0

    Default Re: insert not working

    clarification: i am using 200 for the product id just as a way to test if it gets added. which it has not...

  3. #3
    Join Date
    Feb 2006
    Posts
    116
    Plugin Contributions
    0

    Default Re: insert not working

    well, it seems like the problem might be because the $data[1] has an apostrophe in it. anyway around this?

  4. #4
    Join Date
    Aug 2004
    Posts
    1,590
    Plugin Contributions
    1

    Default Re: insert not working

    Which Zen-Cart version are you using ? I do not see any readings that contains, either, $request1 nor $data[1]. Did you installed a seperated MOD from the downloads contribution of this site ?

  5. #5
    Join Date
    Feb 2006
    Posts
    116
    Plugin Contributions
    0

    Default Re: insert not working

    it is actually from code that i wrote.

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    $counter=40;
    $file = fopen("comp.csv", "r");
    $line=fgets($file);
    $data=explode(',', $line);
    echo $data[1];
    $connection = mysql_connect("localhost", "root", "xxxxxx");
    @mysql_select_db("gcatalog1") or die( "Unable to select database");
    $request1 = "INSERT INTO products_description (products_id,products_name) VALUES (200,$data[1])";
    mysql_query($request1) or Die(mysql_error());

    ?>

    so when $data[1]=test i get the following out put:

    testUnknown column 'test' in 'field list'


    when $data[1]=Ma'alim al-Suluk li al-Mar'a al-Muslima output:

    Ma'alim al-Suluk li al-Mar'a al-MuslimaYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''alim al-Suluk li al-Mar'a al-Muslima)' at line 1

    not sure what to make of it?

  6. #6
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: insert not working

    You need to "escape" those apostrophes.

    Try adding an addslashes() around the variable containing your data with apostrophes.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  7. #7
    Join Date
    Feb 2006
    Posts
    116
    Plugin Contributions
    0

    Default Re: insert not working

    thanks very much. problem solved!!!

    do you know how i can use a script like this to add things to the database that are not in english? ie, i have some proucts that u want to list in arabic. i have the names in a excel worksheet. once makin it into a flat list does not maintain the arabic.

    thanks

  8. #8
    Join Date
    Feb 2006
    Posts
    116
    Plugin Contributions
    0

    Default Re: insert not working

    i saved the file as a unicode text file but when i try tot extract the data it geives me soe funny outputs. for example the first line reads:
    معالم السلوك للمرأة المسلمة

    and then when i read ti with fget and echo it i get:
    معالم السلوك للمرأة المسلمة ㄊ㈳愬⵬慑汵愠⵬慍爧景映⁩慆桤污䴭❡潲ⱦⰱ〲〰〬ㄮⰲ⸱ⰵ⸲㜵㐱㠲㜵ⰱ਍䐊灵楬慣整攠瑮祲✠〲㄰‧潦⁲敫⁹

    the first bit of it is fine but what is after that is some extra stuff. where is that cooing form?

  9. #9
    Join Date
    Feb 2006
    Posts
    116
    Plugin Contributions
    0

    Default Re: insert not working

    i think the prob is that the unicode i was using was not supported.

    what i am trying to do is import a file of names of books into my database instead of entering them one by one. i am using book type by moku. it seems that when you enter books as type book the arabic is represented in the database as hex. whcih menas that i will have to enter them as hex in order for them to display correctly. does anyone know how i can save my data in hex foramt?

  10. #10
    Join Date
    Feb 2006
    Posts
    116
    Plugin Contributions
    0

    Default Re: insert not working

    ok, i have solved the above problem but now have a different issue. i am able to add the books as needed however when i go to the front the books do show up when i click on show all prodcuts and show new products. they show up in but without any information. no titels, authors, weight etc. however, when i click on the specific category everything shows up just fine. i think i missed a table i am suppose to add to. i am using moku's produt type book.

    the tabels i have added to are:
    products
    products_description
    products_to_categories
    product_book_extra
    book_to_authors


    what am i missing?

 

 

Similar Threads

  1. Insert Web Link Not Working?
    By paulssports in forum General Questions
    Replies: 5
    Last Post: 15 Sep 2009, 07:25 PM
  2. Store not displaying as a PHP insert
    By redsky in forum General Questions
    Replies: 5
    Last Post: 2 Mar 2009, 03:40 PM
  3. add to cart not working...currency not working
    By pcdesigns in forum Templates, Stylesheets, Page Layout
    Replies: 9
    Last Post: 12 Jun 2008, 05:03 AM
  4. Insert image into footer but not working.
    By kevinc66 in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 23 Oct 2007, 06:37 AM
  5. 'Insert link' not working
    By Rita in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 4 Jul 2006, 02:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg