Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Sep 2005
    Posts
    153
    Thanks
    34
    Thanked 0 Times in 0 Posts

    Error with my PHP/SQL music store

    Hi
    I've been using a PHP script based music download store on my site for several years. There is now no support for it, instead i just have folders and folders of processes and scripts.
    I can't ask for any specific coding solution here but I'm hoping someone out there can identify what the following problem might be down to.
    Customer buys a download on the store which connects to Paypal. I get a PayPal email confirmation, and the customer gets an automatic email with the download links.
    However the last bit isn't working. There seems to be no email of links being generated or sent anywhere.
    Does any PHP masters out there know what sort of script I need to look for in my folders? Or could such a problem lie elsewhere?

    I usually post up bits of code on this forum to get help with, but this is a bit different and not very specific.

    Still, worth a shot.

    Thanks

  • #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,559
    Thanks
    76
    Thanked 105 Times in 104 Posts
    I can bet it's one of two problems.

    #1. The email address to be sent to is invalid, make sure it's your correct email. If you ever did a script rollback it will be reset.

    #2. A coding error in the mailto function. Possibly a blank variable.
    Been a sign maker for 7 years. My business:
    American Made Signs

  • Users who have thanked myfayt for this post:

    sonofjack (04-19-2012)

  • #3
    Regular Coder
    Join Date
    Sep 2005
    Posts
    153
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Thanks for the reply.
    I'm not sure it is that though as every customer who has tried to purchase has never received an email with the links. And I've just tried buying from it myself and not received anything.
    Also, the admin section of the store contains lists of previous purchases and customers and there is nothing in there. Which indicates the store isn't holding onto the shopping basket items.
    I've reinstalled it all several times thinking it would sort it but it hasn't.

    In the System Preferences page of the Admin section, the two fields that are blank are Proxy Host "for outgoing requests if needed" and Port Of Proxy "(ie: 8080 if needed)".
    I can't recall if these were ever filled in in previous installations.
    Should they be? I'm not 100% as to what they mean

    Otherwise could it be a problem with one of the process files that is meant to save the shopping basket details?

    I've been able to choose download tracks and then go to a "Pay" page which lists the tracks i"ve selected and then takes me via PayPal to pay for them.

  • #4
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    If the code worked for several years and you haven't changed anything about it immediately before this problem cropped up then I would suspect that your host may have upgraded PHP or changed something in their php.ini setup (or something similar) and perhaps some of the code in use is either not working anymore or at least is not working the way it used to work. Some of the syntax or logic may need to be changed (if, for example, a function that used to return 0 now returns false due to a change in the newest version of PHP, but the script is set to test literally for the integer type value of 0 then suddenly that part of the script will break - but probably without generating any errors or warnings).

    Have you checked your server's error logs for new warnings or errors?

    If nothing there makes the problem obvious then you would want to start tracing the problem beginning at your "checkout" page and working step-by-step through to wherever the e-mail generation takes place to see where your script fails. You might want to put your Paypal into sandbox mode for this debugging.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • Users who have thanked Rowsdower! for this post:

    sonofjack (04-19-2012)

  • #5
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,559
    Thanks
    76
    Thanked 105 Times in 104 Posts
    I agree with Rowsdower, upgrading PHP versions can greatly impact your script. I've run into problems like that and also know a forum that was very messed up and corrupted over an upgrade.

    If the products aren't even being inserted into your database, admin table. Then the problem would lie before that query.

    Do the items show up in the shopping cart? If so then it's not passing them on from that. Maybe check to see if they are global variables so they retain throughout the website browsing and purchasing.

    If nothing works, you can post in the classifieds and hire someone to fix it.
    Been a sign maker for 7 years. My business:
    American Made Signs

  • #6
    Regular Coder
    Join Date
    Sep 2005
    Posts
    153
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Thank you.
    That sounds most likely. I was wondering if it might be to do with some upgrade somewhere.
    There are other things that have stopped working in recent months.
    The Send Download button on the admin page now takes me to a error page. Or rather a "the website cannot display the page" page.

    So I need to do some tracing then. This could be interesting as there are folders and folders or all sorts of little files. Inc. files and Inc. files. and lots of SQL tables going on.

    Thank you for your reply. Very helpful.

  • #7
    Regular Coder
    Join Date
    Sep 2005
    Posts
    153
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Posted my last message before I received your reply, myfayt


    I can add new products (download tracks and albums) okay into the database. That bit all works fine.
    I can go through the motions of Buying a song or album and it brings up the basket listing them. I can Pay Now and go through the motions of paying via PayPal and I get the receipt emailed to me.

    But there isn't an email being generated for the customer of what they have bought, and they are not being stored into the Customer list. And as I mentioned there was also a way of sending a download to someone who had previously bought (either as a freebie or to resend to someone who never received it), but that bit of the Admin section doesn't seem to link to anything now.
    The suffix to that URL is pname=DownloadsProcess-Create and I have a Inc file called DownloadsProcess which has the following code.
    It's lengthy but I'll post it as an example. Might be something in here you may well spot.

    Code:
    <?php
    
    require_once (DOCMA_MODULES_HOME."/123-music-admin/actions/prepend.inc");
    require_once (DOCMA_MODULES_HOME."/123-music-admin/lib/DownloadMailGenerator.inc");
    require_once (DOCMA_MODULES_HOME."/paypal/actions/PPPostFindBasket.inc");
    
    /**
     * @version $Id: DownloadsProcess.inc,v 1.6 2003/05/23 12:34:09 ddoubleday Exp $ 
     */
     
    class DownloadsProcess extends Process
    {
    	function init()
    	{
    		////////////////////////////////////////////////////////////////////////
    		// Show Send Form
    		////////////////////////////////////////////////////////////////////////
    		
     		$albumFinder = new FindAllBeans(
    			array("BeanName" => "Bundle"),
    			array("BundleIter" => "Albums"));
     		$songFinder = new FindAllBeans(
    			array("BeanName" => "Product"),
    			array("ProductIter" => "Songs"));
            $mailinglistFinder = new FindAllBeans(
    			array("BeanName" => "Mailinglist"),
    			array("MailinglistIter" => "Mailinglists"));
    			
    		$bf = new BeanFormatter(
    			array("Albums" => BF_EXTENSIBLE, "Songs" => BF_EXTENSIBLE, 
                    "Mailinglists" => BF_EXTENSIBLE));
    			
    		$ia1 = new Interaction("admin/send_download");
    		
    		$albumFinder->connect($songFinder);
    		$songFinder->connect($mailinglistFinder);
    		$mailinglistFinder->connect($bf);
    		$bf->connect($ia1);
    		
    		$this->register($albumFinder, "Create", "USER");		
    		
    		////////////////////////////////////////////////////////////////////////
    		// Send the message
    		////////////////////////////////////////////////////////////////////////
    		
    		$validator = new ValidateValues(array(
    			"download" => array("checkDownloadID"),
    			"email" => array("checkReceiver")));
    		$downloadFinder = new Callback(array("Function" => "determineDownload"));
    					
    		$generateMails = new GenerateMails();
            $determineSiteEmail = new Callback(array("Function" => "determineSiteEmail"));
    		$sendMail = new SendMail(
    			array(), 
    			array("Subject" => "subject",				
    				"Format" => "format",
    				"TimeDelay" => "time_delay"));
    						
    		$iaContinue = new IAContinue("admin/success", 
    			array("SessionData" => array()), 
    			array("p1" => "EmailsSent"));
    			
    		$deleteForm = new RemoveValues(array("Key" => "email"));        
    		
    		$validator->connect($downloadFinder);
    		$validator->connect($albumFinder, ACTION_ERROR);		
    		$downloadFinder->connect($generateMails);
            
    		$generateMails->connect($determineSiteEmail);
    		$determineSiteEmail->connect($sendMail);
            $sendMail->connect($iaContinue);
    		$iaContinue->connect($deleteForm);
            $deleteForm->connect($albumFinder);
    		
    		$this->register($validator, "Send", "USER");
    		$this->register($iaContinue, "Continue", "USER");
    				
    		////////////////////////////////////////////////////////////////////////
    		// Handle a download request
    		////////////////////////////////////////////////////////////////////////
    		
    		// find the downloadlink
    		$songGetter = new GetDownload();
    		$download = new DownloadFile();
    		$determineIP = new Callback(array("Function" => "determineIP"));
    		$incrAttempt = new Callback(array("Function" => "incrementAttempt"));
    		$stop = new StopNode();
    		$ia3 = new Interaction("admin/download_error");
    		
    		$songGetter->connect($download);
    		$songGetter->connect($ia3, ACTION_ERROR);
    		$download->connect($determineIP);
    		$determineIP->connect($incrAttempt);
    		$incrAttempt->connect($stop);
    		
    		$this->register($songGetter, "Download");
    		
    		////////////////////////////////////////////////////////////////////////
    		// Show the download links
    		////////////////////////////////////////////////////////////////////////
    		
    		$dlFinder = new SearchBeansByProperty(
    			array("BeanName" => "Downloadlink"),
                array("Property" => "search",
                      "OrderBy" => "created desc"));
    		$dlFormatter = new BeanFormatter(array("DownloadlinkIter" => false));
    		$determineLinkStatus = new Callback(
    			array("Function" => "determineLinkStatus"));
    		$ia4 = new Interaction("admin/show_download_links");
    		
    		$dlFinder->connect($dlFormatter);
    		$dlFormatter->connect($determineLinkStatus);
    		$determineLinkStatus->connect($ia4);
    		
    		$this->register($dlFinder, "Start", "USER");
    		
    		////////////////////////////////////////////////////////////////////////
    		// Browse the links
    		////////////////////////////////////////////////////////////////////////
    		
    		$pager = new GetPageable(array("IterName" => "DownloadlinkIter"));
    		
    		$pager->connect($dlFormatter);
    		
    		$this->register($pager, "Browse", "USER");
    		
    		////////////////////////////////////////////////////////////////////////
    		// Delete a link
    		////////////////////////////////////////////////////////////////////////
    		
    		$delete = new DeleteBean(array("BeanName" => "Downloadlink"));
    		$delete->connect($dlFinder);
    		
    		
    		$this->register($delete, "Delete");
    	}
    	
    	function PaypalNotification()
    	{
            // debug start
            $this->executeAction("PPPostFindBasket");
            
            // debug end
            $conf =& config_get_config();
            
    		// get the paypal basket
    		$basket =& $this->get("PPBasket");
    		$payerEmail = $basket->getValue("payer_email");
    		$customer = $basket->getValue("address_name");
            if (! $customer)
            {
                $customer = $basket->getValue("first_name") . " " . 
                    $basket->getValue("last_name");
            }
            
            // last fallback
            if (! $customer)
            {
                $customer = "Customer";
            }
            
    		$numCartItems = $basket->getValue("num_cart_items");
            $mailFormat = $conf["downloadmail.format"];
            $mailBody = ($mailFormat == "html") 
                ? $conf["downloadmail.mailbody.html"] : $conf["downloadmail.mailbody.text"];
            
            $subject = "Your ".$conf["generalinfo.sitename"]." Music Downloads";
            $this->put("Subject", $subject);
    		$generator = new DownloadMailGenerator($mailBody, $mailFormat);
    		$songManager =& BeanManager::getManager("Product");
    		$albumManager =& BeanManager::getManager("Bundle");
    		
            
            // temp array for all albums to subscribe user to the corresponding 
            // mailing lists.
            $mlalbums = array();
            echo("num cart items: $numCartItems<br>");
    		for ($i=1; $i<=$numCartItems; $i++)
    		{
    			$idSpec = split(":", $basket->getValue("item_number_".$i));
                echo("id spec is: " . $idSpec[0] . "<br>");
    			if ($idSpec[0] == "song")
    			{
                    echo("its a song");
    				$song =& $songManager->find($idSpec[1]);
                    
                    $albums = $song->getAssignedBeans("bundle");
                    echo("albums: $albums");
                    // walk through the albums
                    while ($albums->next()) {
                        $album = $albums->getBean();
                        echo("adding album<br>");
                        $mlalbums[] = $album;
                    }
    				$generator->addProduct($song);
    			}
    			else if ($idSpec[0] == "album")
    			{
    				$album =& $albumManager->find($idSpec[1]);
                    $mlalbums[] = $album;
    				$generator->addBundle($album);
    			}
    			else
    			{
    				// hmpf
    			}
    		}
    
            for ($i=0; $i<sizeof($mlalbums); $i++) {
                // add customer to mailinglist
                $album = $mlalbums[$i];
                $mailingList =& $album->getParent("mailinglist");
                if ($mailingList)
                {
                    // check if buyer already subscribed to the list 
                    $subscriber = $mailingList->getAssignedBeans("subscriber", null, 
                        array("email_adress" => $payerEmail));
                    if (! $subscriber->next())
                    {
                        // add
                        $subscriberManager =& BeanManager::getManager("Subscriber");
                        $newSubscriber = $subscriberManager->create(
                            array("first_name" => $basket->getValue("first_name"), 
                                "last_name" => $basket->getValue("last_name"), 
                                "email_adress" => $payerEmail));
                        $mailingList->assignBean($newSubscriber);
                    }
                }
            }
            
    		$mail = $generator->generateMail($payerEmail, $customer);
    		$subject = $this->get("Subject");
    		$format = $this->get("Format", "text");
    		$timeDelay = $this->get("TimeDelay");
    		$this->put("Recipient", $payerEmail);
    		$this->put("Message", $mail);			
    		$this->determineSiteEmail();
    		$retval = $this->executeAction("SendMail");
            
            // write customer data
            $customerMgr =& BeanManager::getManager("Customer");
            $purchaseMgr =& BeanManager::getManager("Purchase");
            // try to get the customer by email
            $customer =& $customerMgr->findByKey("email", $payerEmail);
            if (!$customer)
            {
                $customer =& $customerMgr->create(
                    array("email" => $payerEmail, "nr_purchase" => 1, 
                        "fname" => $basket->getValue("first_name"), "lname" => $basket->getValue("last_name")));
            }
            else
            {
                // incr nr_purchase
                $nr_purchase = $customer->get("nr_purchase");
                $customer->set("nr_purchase", ++$nr_purchase);
            }
            
            // set last purchase
            $customer->set("last_purchase", date("Y-m-d"));
            
            // create the purchase info
            $purchase = $purchaseMgr->create(array
                ("payment_id" => $basket->getValue("id"),
                 "date" => date("Y-m-d"),
                 "currency" => $basket->getValue("mc_currency"),
                 "amount" => $basket->getValue("mc_gross")));
                 
            $customer->assignBean($purchase);
                          
    		return ACTION_DONE;
    	}
    	
        
        /**
         *
         */
        function determineSiteEmail()
        {
            $conf =& config_get_config();
            $this->put("Sender", $conf["generalinfo.siteemail"]);
        }
        
    	/**
    	 * Callback method to check if either email or mailing list is
    	 * selected
    	 */	
    	function checkReceiver($params)
    	{
    		if ($this->get("receiver") == "email")
    		{
    			return (bool) ($this->get("email"));
    		}
    		else
    		{
    			return (bool) ($this->get("mailinglist"));
    		}
    	}
    	
    	/**
    	 * Callback method to check if either album or song is
    	 * selected
    	 */	
    	function checkDownloadID($params)
    	{
    		if ($this->get("song_download") > 0)
    		{
    			return (bool) ($this->get("album_download") == 0);
    		}
            else if ($this->get("album_download") > 0)
            {
                return (bool) ($this->get("song_download") == 0);
            }
    		else
    		{
    			return false;
    		}
    	}
    
    	/**
    	 * Callback method to determine the IP of the caller
    	 */
    	 
    	function determineIP()
    	{
    		$link =& $this->get("Downloadlink");
            if ($link)
            {
                $link->set("ip", $_SERVER["REMOTE_ADDR"]);
            }
    	}
    	
    	/**
    	 * Callback method to increment the download attempt
    	 */
    	 
    	function incrementAttempt()
    	{
    		$link =& $this->get("Downloadlink");
            if ($link)
            {
                $attempt = $link->get("attempts");
                $link->set("attempts", $attempt+1);
            }
    	}
    	
    	/**
    	 * Callback method to set the link status
    	 */
    	 
    	function determineDownload()
    	{
    		if ($this->get("song_download") > 0)
    		{
                $mgrName = "Product";
                $id = $this->get("song_download");
                $type = "Song";
    		}
            else
            {
                $mgrName = "Bundle";
                $id = $this->get("album_download");
                $type = "Album";
            }
            $mgr =& BeanManager::getManager($mgrName);
            $bean =& $mgr->find($id);
            $this->put("DownloadType", $type);
            $this->put("Download", $bean);
    	}
        
        /**
    	 * Callback method to set the link status
    	 */
    	 
    	function determineLinkStatus()
    	{
    		$links =& $this->get("DownloadlinkIter");
    		for ($i=0; $i<count($links); $i++)
    		{
    			$link =& $links[$i];
    			if ($link["expire"] && time() > $link["expire"])
    			{
    				$link["status"] = "EXPIRED";
    			}
    			else if ($link["attempts"] >= $link["link_limit"])
    			{
    				$link["status"] = "EXPIRED";
    			}
    			else
    			{
    				$link["status"] = "ACTIVE";
    			}
    		}
    	}
    }
    ?>

  • #8
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Seriously, step 1 here is to check your error logs.

    Now that you've posted this additional information (status 500 error code, which is what I am assuming you mean by "the website cannot display the page" page) you're giving me the idea that the problem might not even be something you (or any coder here) can fix. You may need to open a trouble ticket with your host - but first there are some things you should check.

    Status 500 errors are typically the result of trouble in .htaccess files, php.ini files, or folder permissions not being what they should be for the operations being used. You might try temporarily renaming any .htaccess or php.ini files in the target directory and any parent directories and see if the problem goes away. If so, you know where to look. If not, then remember to change those files back to their old names. Then go ahead and try again, just so you can create a fresh line in the log files to look at. The log file should show the exact file and line number of the offending code along with the exact failure that occurred. Finding that entry in the log is waaaaay better than poking around line-by-line manually through dozens of files to see if something jumps off of the page at you.

    Now, bear in mind, if the host has done something strange then they may have a problem in their shop that they have to fix on their own. Your code *might* be totally fine. But we won't know that until we check.

    So check all of your logs (if your host has a cPanel, it's probably an item somewhere in there) and look for something to dig into... Post the log results from a failed purchase here, if you can't find anything to work with.

    Then, if we still come up empty you should contact your host for assistance.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • Users who have thanked Rowsdower! for this post:

    sonofjack (04-19-2012)

  • #9
    Regular Coder
    Join Date
    Sep 2005
    Posts
    153
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Hi

    The store was purchased a few years ago and came to me in a zip file. Then I followed the installation instructions - uploading to my webspace, running the install page, changing permissions, putting in details etc. So it all stands alone on my web directory which is hosted by Dreamhost.
    But the company/person who built the software and initially offered support has now disappeared. So I'm stuck on my own with it now. Well just me and the good posters on Coding Forums
    So bits of the code may well be outdated now since Dreamhost have updated PHP and SQL or whatever. It's just down to me to sort through what code I can change. Would the code I posted earlier be one of the bits I need to amend do you think?
    I shall also follow your advice re: error logs, .htaccess etc
    One of the first things to do in the installation process was rename the rename_.htaccess file to .htaccess


  •  

    Posting Permissions

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