SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast daverozelle's Avatar
    Join Date
    Mar 2003
    Location
    Western, PA - USA
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help I broke my site!

    I am still unable to locate the fault or break that is causing me to lose money every month. I am a hosting reseller with a handful of customers that basically pay to support my hobby/habit of site design. Help me please!

    I have a site that I built a few years ago based on the 'plaincart' PHP/MySQL shopping cart. The site and the system has worked fine for years. Now I need to move my clients to a new hosting environment, and this is the last customer that I can't move. One function does not work, and I don't know why.

    What happens on the new hosting site is that when I click the 'Add to Cart' button calling the addtocart() function, it loops and adds 21 items to the cart before Firefox stops the loop. This does not happen on the old host. No code has changed, only the server. I am including the phpinfo() from both environments for comparison, as well as the link to the original plaincart add to cart information page to show the code I'm dealing with.

    http://www.phpwebcommerce.com/shop-add-to-cart.php

    Original (and working) PHP Info:
    PHP Version 5.2.2

    System FreeBSD unix20.hsphere.cc 6.3-RELEASE-p1 FreeBSD 6.3-RELEASE-p1 #1: Thu Feb 21 08:15:46 EST 2008

    Build Date May 24 2007 11:00:37

    Configure Command './configure' '--enable-versioning' '--with-layout=GNU' '--with-config-file-scan-dir=/usr/local/etc/php' '--disable-all' '--enable-libxml' '--with-libxml-dir=/usr/local' '--enable-reflection' '--program-prefix=' '--enable-fastcgi' '--with-apxs=/usr/local/sbin/apxs' '--with-regex=php' '--with-zend-vm=CALL' '--prefix=/usr/local'

    Server API CGI/FastCGI
    Virtual Directory Support disabled
    Configuration File (php.ini) Path /usr/local/etc
    Loaded Configuration File /usr/local/etc/php.ini
    Scan this dir for additional .ini files /usr/local/etc/php
    additional .ini files parsed /usr/local/etc/php/extensions.ini
    PHP API 20041225
    PHP Extension 20060613
    Zend Extension 220060519
    Debug Build no
    Thread Safety disabled
    Zend Memory Manager enabled
    IPv6 Support enabled

    Registered PHP Streams compress.bzip2, compress.zlib, php, file, data, http, ftp Registered Stream Socket Transports tcp, udp, unix, udg

    Registered Stream Filters bzip2.*, zlib.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed


    New PHP Info
    PHP Version 5.2.4

    System Linux web12.hspheredns.com 2.6.18-53.1.13.el5 #1 SMP Tue Feb 12 13:02:30 EST 2008 x86_64

    Build Date Sep 16 2007 16:54:20

    Configure Command './configure' '--localstatedir=/var/hsphere/php' '--with-bz2=/hsphere/shared' '--enable-ctype' '--enable-dba' '--enable-ftp' '--with-gettext=/hsphere/shared' '--enable-mbstring=all' '--with-gd' '--with-mhash=/hsphere/shared' '--with-mcrypt=/hsphere/shared' '--with-openssl=/usr' '--enable-overload' '--enable-posix' '--enable-session' '--enable-sockets' '--enable-standard' '--enable-tokenizer' '--with-xml=/hsphere/shared' '--with-xsl=/hsphere/shared' '--with-zip=/hsphere/shared' '--with-zlib=/hsphere/shared' '--with-zlib-dir=/hsphere/shared' '--with-freetype-dir=/hsphere/shared' '--with-png-dir=/hsphere/shared' '--with-jpeg-dir=/hsphere/shared' '--with-expat-dir=/hsphere/shared' '--with-iconv-dir=/hsphere/shared' '--with-libxml-dir=/hsphere/shared' '--enable-gd-native-ttf' '--with-ttf' '--enable-mbstr-enc-trans' '--with-expat-dir=/hsphere/shared' '--with-xslt-sablot=/hsphere/shared' '--with-gnu-ld' '--with-curl=shared,/hsphere/shared' '--with-curlwrappers' '--with-dom=shared,/hsphere/shared' '--with-dom-xslt=/hsphere/shared' '--with-dom-exslt=/hsphere/shared' '--with-dom=shared,/hsphere/shared' '--with-fileinfo=shared,/hsphere/shared' '--with-gmp=shared,/hsphere/shared' '--with-iconv=shared,/hsphere/shared' '--with-imap=shared,/hsphere/shared' '--with-mcal=shared,/hsphere/shared' '--with-mysql=shared,/usr' '--with-mysqli=shared' '--with-pgsql=shared,/usr' '--with-sqlite=shared' '--with-unixODBC=shared,/hsphere/shared' '--with-xmlrpc=shared' '--enable-track-vars' '--enable-trans-sid' '--enable-memory-limit' '--enable-force-cgi-redirect' '--enable-fastcgi' '--with-config-file-path=/hsphere/local/config/httpd/php5' '--with-config-file-scan-dir=/hsphere/local/config/httpd/php5/php.d' '--enable-magic-quotes' '--with-pear=/hsphere/shared/apache/libexec/php5ext/php' '--with-mime-magic=/hsphere/local/config/httpd/magic' '--with-inifile' '--with-flatfile' '--prefix=/hsphere/shared/php5' '--with-apxs=/hsphere/shared/apache/bin/apxs' '--enable-cli'

    Server API Apache
    Virtual Directory Support disabled
    Configuration File (php.ini) Path /hsphere/local/config/httpd/php5
    Loaded Configuration File /usr/local/Zend/etc/php.ini
    Scan this dir for additional .ini files /hsphere/local/config/httpd/php5/php.d

    additional .ini files parsed /hsphere/local/config/httpd/php5/php.d/bcmath.ini, /hsphere/local/config/httpd/php5/php.d/calendar.ini, /hsphere/local/config/httpd/php5/php.d/curl.ini, /hsphere/local/config/httpd/php5/php.d/dbase.ini, /hsphere/local/config/httpd/php5/php.d/exif.ini, /hsphere/local/config/httpd/php5/php.d/fileinfo.ini, /hsphere/local/config/httpd/php5/php.d/gmp.ini, /hsphere/local/config/httpd/php5/php.d/iconv.ini, /hsphere/local/config/httpd/php5/php.d/imap.ini, /hsphere/local/config/httpd/php5/php.d/ldap.ini, /hsphere/local/config/httpd/php5/php.d/mysql.ini, /hsphere/local/config/httpd/php5/php.d/mysqli.ini, /hsphere/local/config/httpd/php5/php.d/ncurses.ini, /hsphere/local/config/httpd/php5/php.d/odbc.ini, /hsphere/local/config/httpd/php5/php.d/pcntl.ini, /hsphere/local/config/httpd/php5/php.d/pgsql.ini, /hsphere/local/config/httpd/php5/php.d/pspell.ini, /hsphere/local/config/httpd/php5/php.d/shmop.ini, /hsphere/local/config/httpd/php5/php.d/soap.ini, /hsphere/local/config/httpd/php5/php.d/sqlite.ini, /hsphere/local/config/httpd/php5/php.d/sysvmsg.ini, /hsphere/local/config/httpd/php5/php.d/sysvsem.ini, /hsphere/local/config/httpd/php5/php.d/sysvshm.ini, /hsphere/local/config/httpd/php5/php.d/xmlrpc.ini, /hsphere/local/config/httpd/php5/php.d/zmnogosearch.ini

    PHP API 20041225
    PHP Extension 20060613
    Zend Extension 220060519
    Debug Build no
    Thread Safety disabled
    Zend Memory Manager enabled
    IPv6 Support enabled
    Registered PHP Streams php, file, data, compress.bzip2, compress.zlib, https, ftps, tftp, ftp, telnet, dict, ldap, http

    Registered Stream Socket Transports tcp, udp, unix, udg, ssl, sslv3, sslv2, tls

    Registered Stream Filters string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, bzip2.*, zlib.*, convert.iconv.*


    ------------
    The only big difference I can see is the Server API, would that cause this? I'm having a redirect issue somewhere in the function or code, so I didn't think so, but I am not familiar with this side fo things. Please help.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just took a quick glance, but heres initial observations without me actually checking any code logic.

    header() does not stop script execution. You need to call exit; after sending a redirect header unless you want the script to keep running(unlikely you want that). You should also always call session_write_close() before sending a redirect header, otherwise you may risk data loss due to race conditions. You should do this regardless of whether it fixes the immediate problem.

    Also, theres a redirect in there that uses a variable for the location. Are you sure this variable has a suitable value? use var_dump() on it to find out. the browser might interpret an empty location as meaning reload the current url, which would cause this problem.

    Also, check the php error_log

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    To be honest that script doesn't look very good, but that doesn't help you with this problem.

    After the first line of the addtocart function, put:
    PHP Code:
    exit('Not Here'); 
    If the script exits and you see 'Not Here', then the problem isn't with the above code. Remove the exit line and put it after the next line. Keep going until it loops, not displaying the line.

    That line will be where the problem is. Paste it here then we can progress.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    SitePoint Enthusiast daverozelle's Avatar
    Join Date
    Mar 2003
    Location
    Western, PA - USA
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    To be honest that script doesn't look very good, but that doesn't help you with this problem.

    After the first line of the addtocart function, put:
    PHP Code:
    exit('Not Here'); 
    If the script exits and you see 'Not Here', then the problem isn't with the above code. Remove the exit line and put it after the next line. Keep going until it loops, not displaying the line.

    That line will be where the problem is. Paste it here then we can progress.
    Thank you... the simple was quickly overlooked in my frustration. The exit() was tedious but much easier than fighting the whole system. I found that the loop was being caused from the deleteAbandonedCart() which is odd to me.

    I was working on rebuilding the site, and everything worked great on the first order test, but after that it died. And I assume it has something to do with trying to delete an old cart and looping at that point for some reason. I don't get it, but as far as I can tell - that delete function is not necessary here anyway. Shouldn't something like this be called after order confirmation is completed - thus ensuring the cart can be deleted since that order session is complete?

  5. #5
    SitePoint Enthusiast daverozelle's Avatar
    Join Date
    Mar 2003
    Location
    Western, PA - USA
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another problem! This was not an issue on the old system, but it is on the new. Here is some code from a function that takes all of the order information and creates a very simple text email that is sent to both parties. I get the following error while parsing:

    ERROR
    Warning: extract(): First argument should be an array in /library/checkout-functions.php on line 135
    CODE
    Code:
    function orderemail ($orderId)
        {
            $order_disclaimer = '
                Placing an order does not guarantee fulfillment.
            ';
            
            // get ordered items
            $sql = "SELECT pd_name, pd_price, od_qty
                    FROM tbl_order_item oi, tbl_product p 
                    WHERE oi.pd_id = p.pd_id and oi.od_id = $orderId
                    ORDER BY od_id ASC";
            
            $result =& dbQuery($sql);
            $orderedItem = array();
            while ($row =& dbFetchAssoc($result)) {
                $orderedItem[] = $row;
            }
            
            // get order information
            $sql = "SELECT od_date, od_last_update, od_status, od_shipping_first_name, od_shipping_last_name, od_shipping_address1, 
                           od_shipping_address2, od_shipping_city, od_shipping_state, od_shipping_postal_code, od_shipping_phone, od_email, od_paymentmethod, od_comments
                    FROM tbl_order 
                    WHERE od_id = $orderId";
            
            $result =& dbQuery($sql);
    
            extract(dbFetchAssoc($result));
    I tried to read the proper way to use extract() but I am not savvy enough to make this work. I am a victim of something that used to work that doesn't again. Please help me.

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dbFetchAssoc() needs to return an array so that extract() can use it. Examine the function to see what might cause it to not return an array. It may have somethign to do with your $result variable.

  7. #7
    SitePoint Enthusiast daverozelle's Avatar
    Join Date
    Mar 2003
    Location
    Western, PA - USA
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    dbFetchAssoc() needs to return an array so that extract() can use it. Examine the function to see what might cause it to not return an array. It may have something to do with your $result variable.
    Problem is I know enough PHP to follow along but not really code it, and I haven't changed this functions code at all. It worked on a different server, and I don't really know how to examine the function the way you advise. I honestly have no idea what to do with this error.

  8. #8
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If you var_dump the return of the function, it will tell you what the function returns:
    PHP Code:
    var_dump(dbFetchAssoc($result)); 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  9. #9
    SitePoint Enthusiast daverozelle's Avatar
    Join Date
    Mar 2003
    Location
    Western, PA - USA
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    If you var_dump the return of the function, it will tell you what the function returns:
    PHP Code:
    var_dump(dbFetchAssoc($result)); 
    Where exactly do I put that code to output the dump?

    EDIT

    OK, I added your line of code directly before the extract() and then commented out the extract(). Now when I try to process the send_email function I get this error:

    PHP Code:
    bool(false
    Last edited by daverozelle; Dec 29, 2008 at 12:29. Reason: update

  10. #10
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var_dump($result);
    and post the code which defines the dbFetchAssoc() function.

    I think your query is failing somewhere.

  11. #11
    SitePoint Enthusiast daverozelle's Avatar
    Join Date
    Mar 2003
    Location
    Western, PA - USA
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    var_dump($result);
    and post the code which defines the dbFetchAssoc() function.

    I think your query is failing somewhere.
    OK, now I am real confused. var_dump($result) should return my data right? Because when I added var_dump($result) where I had the extract(), I get this returned:
    PHP Code:
    resource(21of type (mysql result
    And this is the code for dbFetchAssoc()
    PHP Code:
    function dbFetchAssoc($result)
    {
        return 
    mysql_fetch_assoc($result);


  12. #12
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Given the definition of your dbFetchAssoc() function, the value of $result appears proper.

    Seems like your problem is that this query just simply doesn't produce any results
    PHP Code:
     $sql "SELECT od_date, od_last_update, od_status, od_shipping_first_name, od_shipping_last_name, od_shipping_address1, 
                           od_shipping_address2, od_shipping_city, od_shipping_state, od_shipping_postal_code, od_shipping_phone, od_email, od_paymentmethod, od_comments
                    FROM tbl_order 
                    WHERE od_id = 
    $orderId"
    use var_dump($orderId) to make sure the value is really an order number. You also should now go and check your database to make sure such an entry exists. The other query probably isn't returning any results either.


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
  •