Results 1 to 10 of 10

Hybrid View

  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,444
    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.

 

 

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