Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2006
    Posts
    420
    Plugin Contributions
    0

    Default php code to update database HELP pls

    Hi all , i am trying to write some basic code to update stock qtys from a XML file ..

    I am so close .. just stumbled at the last hurdle ( i think ) Can anyone help ...

    I am parsing the XML correctly as it echos up to the screen just fine , so I have something like :-

    Code:
    connection string and select DB 
    
    Start the xml reading array ...
    
    populate $productcode and $stock from XML 
    
    echo to the page ... all fine 
    
     $ins_product = addslashes($productcode);
     $ins_qty = addslashes($stock);
    
    $result= mysql_query("UPDATE 'products' SET products_quantity = '$ins_qty' WHERE 'products_model = '$ins_product'");
    
    loop back to the beginning of the array

    the result is all the correct info gets echo'd up to the page , but the update query does nothing.


    ANy hints please ?
    Various Zen cart sites !

  2. #2
    Join Date
    Jan 2006
    Posts
    420
    Plugin Contributions
    0

    Default Re: php code to update database HELP pls

    just wanted to add that the query works if I use real numbers

    $result= mysql_query("UPDATE products SET products_quantity = 70 WHERE products_model = 26284");

    and the variables echoed to the page contain those same numbers ..

    but when I replace the numbers with the variables , it does nothing.

    thanks for looking
    Various Zen cart sites !

  3. #3
    Join Date
    Jan 2008
    Posts
    1,700
    Plugin Contributions
    6

    Default Re: php code to update database HELP pls

    How about this?

    PHP Code:
    $query "UPDATE products SET products_quantity = '" $ins_qty "' WHERE products_model = '" $ins_product "'";
    $result $db->Execute($query); 

  4. #4
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: php code to update database HELP pls

    Quote Originally Posted by Steven300 View Post
    How about this?

    PHP Code:
    $query "UPDATE products SET products_quantity = '" $ins_qty "' WHERE products_model = '" $ins_product "'";
    $result $db->Execute($query); 

    That code errors with the following:

    [Sat Oct 3 09:50:29 2009] [error] PHP Fatal error: Call to a member function Execute() on a non-object in /home/overplan/public_html/mirror/smiffy.php on line 44

    ??? any more suggestions? really desperate to get this to work. It makes no sense to me that when the following is used:
    $query= mysql_query("UPDATE products SET products_quantity = 5 WHERE products_model = 00380");
    it updates the database fine.

    Yet when you replace the actual numbers with the vaiables:
    $query= mysql_query("UPDATE products SET products_quantity = $ins_qty WHERE products_model = $ins_product");

    it just doesnt work. as crazycucumber said, when you echo $ins_qty and $ins_product it returns all the correct vaulues, SO WHY WONT IT INSERT INTO AND COMPARE IN THE DATABASE arghhhhhhh!!??

  5. #5
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: php code to update database HELP pls

    Quote Originally Posted by philip937 View Post
    That code errors with the following:

    [Sat Oct 3 09:50:29 2009] [error] PHP Fatal error: Call to a member function Execute() on a non-object in /home/overplan/public_html/mirror/smiffy.php on line 44

    ??? any more suggestions? really desperate to get this to work. It makes no sense to me that when the following is used:
    $query= mysql_query("UPDATE products SET products_quantity = 5 WHERE products_model = 00380");
    it updates the database fine.

    Yet when you replace the actual numbers with the vaiables:
    $query= mysql_query("UPDATE products SET products_quantity = $ins_qty WHERE products_model = $ins_product");

    it just doesnt work. as crazycucumber said, when you echo $ins_qty and $ins_product it returns all the correct vaulues, SO WHY WONT IT INSERT INTO AND COMPARE IN THE DATABASE arghhhhhhh!!??


    Also, interesting, just tested the following code which uses variables:

    $query= mysql_query("UPDATE products SET products_quantity = $howmany WHERE products_model = $productis");

    but set them manually
    $howmany = '5000';
    $productis = '00384';

    this also works....

    Im so close, what am I missing!!!

  6. #6
    Join Date
    Aug 2009
    Location
    Bedford, England
    Posts
    966
    Plugin Contributions
    0

    Default Re: php code to update database HELP pls

    ok proper weirded out now. its now working, and not sure ive actually changed anything..

    this is what is working now:

    $query= mysql_query("UPDATE products SET products_quantity = $stock WHERE products_model = $productcode");

    will keep you posted if this randomly stops working the same as it started!

 

 

Similar Threads

  1. Update to 1.3.8a Probblems after Database Update
    By wirnsperger in forum Installing on a Linux/Unix Server
    Replies: 0
    Last Post: 4 Feb 2010, 06:41 PM
  2. Code help, pls - how do I reverse the order of these 2 radio buttons?
    By haostaff in forum Templates, Stylesheets, Page Layout
    Replies: 7
    Last Post: 30 Jan 2010, 04:59 AM
  3. Missing configure.php (Pls. help me!!!)
    By angelo1969 in forum Basic Configuration
    Replies: 3
    Last Post: 16 Jul 2008, 09:24 PM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR