We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 47666
    • 43 Posts
    I'm getting an error when my form is processing. The form works fine in the static version, but in modX I'm occasionally getting errors. The frustrating thing is I can't constantly reproduce it. Some times I get the error other times it works fine.

    Here are some of the recent errors in the

    [2014-08-27 20:05:43] (ERROR in xPDOConnection::connect @ /home3/haas12/public_html/bestsellinginsurance.com/core/xpdo/xpdo.class.php : 3043) SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (11)
    [2014-08-27 20:05:43] (ERROR @ /index.php) Error preparing statement for query: SELECT `modSession`.`id` AS `modSession_id`, `modSession`.`access` AS `modSession_access`, `modSession`.`data` AS `modSession_data` FROM `modx_session` AS `modSession` WHERE `modSession`.`id` = ? -
    [2014-08-27 20:05:43] (ERROR in xPDOConnection::connect @ /home3/haas12/public_html/bestsellinginsurance.com/core/xpdo/xpdo.class.php : 3043) SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (11)
    [2014-08-27 20:05:43] (ERROR in xPDOConnection::connect @ /home3/haas12/public_html/bestsellinginsurance.com/core/xpdo/xpdo.class.php : 3043) SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (11)
    [2014-08-27 20:05:43] (ERROR @ /index.php) Error preparing statement for query: SELECT `modSession`.`id` AS `modSession_id`, `modSession`.`access` AS `modSession_access`, `modSession`.`data` AS `modSession_data` FROM `modx_session` AS `modSession` WHERE `modSession`.`id` = ? -
    [2014-08-27 20:05:43] (ERROR in xPDOConnection::connect @ /home3/haas12/public_html/bestsellinginsurance.com/core/xpdo/xpdo.class.php : 3043) SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (11)
    [2014-08-27 20:05:43] (ERROR in xPDOConnection::connect @ /home3/haas12/public_html/bestsellinginsurance.com/core/xpdo/xpdo.class.php : 3043) SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (11)

    I'm not sure what these errors mean, but it looks like it's something with the connection to the database used to store form data.

    Here is the javascript that processes the form:
    $.ajax({
            type: "POST",
            url: "[[++site_url]][[~17]]",
            data: $('.home1').serialize(),
            success: function(msg){
                
                var product= document.home1.product.value;
                product=product.trim();
                
                switch (product) {
                  case "Life":
                    document.location.href = '[[~23]]';
                    break;
                  default:
                    document.location.href = '[[~10]]';
                    break;
                }// end switch 
                          
            },
            error: function(){
              alert("error");
            }
          });//close ajax
    



    Here is the resource [~17]
    [[!process-step1]]
    


    process-step1 snippet : i think the problem might be in here when is tries to connect to the database.
    <?php
    require_once 'assets/scripts/database_connection.php';
    require_once 'assets/scripts/clean_up.php';
    
    // ensure zip and product have values
    if(isset($_POST['zip'])&& isset($_POST['product'])){
    	$zip = mr_clean($_POST['zip']);
    	$product = mr_clean($_POST['product']);
    	$ipLocation = mr_clean($_POST['ipLocation']);
            
        // match city state with zipcode
    	$query = "SELECT * FROM zipcodes WHERE zipcode = ".$zip.";";
        $result = mysql_query($query);
        $num_rows = mysql_num_rows($result);
        
        if($num_rows == 1){
        $location = mysql_fetch_array( $result );
        $zipLocation = $location['city'].', '.$location['state'];
            $city = strtolower($location['city']);
            $city = ucwords($city);
            $_SESSION['city'] = $city;
             	 	    
        } //close if($num_rows == 1) 
    
    	
    	$_SESSION['product'] = $product;
    	$date = date('Y-m-d H:i:s');
    
        // enter into database
        $query = "INSERT INTO bsi_lead ( ip, zip, product, submissionDate, ipLocation, zipLocation)
        VALUES( '$ip', '$zip', '$product','".$date."','$ipLocation', '$zipLocation');";
    	$result = mysql_query($query)
    		or die(mysql_error());
    	// get id fom insert
    	$_SESSION['id'] = mysql_insert_id();
    	mysql_close($con);
     
    }
    else{
        echo "no post";
    }
    



    I have tried to figure out how to get better error messages, but I haven't come across easy to follow directions anywhere. Any ideas?

    MODX Revolution 2.3.1-pl (traditional)
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      That looks like an overloaded server. Is this shared hosting?

      There may be some ways you can reduce the page's load on the server.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 47666
        • 43 Posts
        Quote from: sottwell at Aug 28, 2014, 02:16 PM
        That looks like an overloaded server. Is this shared hosting?

        There may be some ways you can reduce the page's load on the server.

        Yes, I have a hostgator hosting account with several websites on it. So you think that is the problem? Too much bandwidth used on the server?
          • 47666
          • 43 Posts
          Sottwell, I came across a post where you mentioned you were switching to SSD hosting with a2. Was the SSD hosting much faster for MODX? Do you think that would make a difference with the problem I'm having?

          https://forums.modx.com/thread/?thread=85237&page=2 [ed. note: aaron4osu last edited this post 12 years, 1 month ago.]
            • 3749
            • 24,544 Posts
            I think any of these would probably be better than Hostgator:

            http://bobsguides.com/modx-friendly-hosts.html
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              I prefer SkyToaster myself, but any of the ones Bob lists would be better than Hostgator. I have had several cases of Hostgator not playing will with MODX lately. When you consider that the "cheaper" hosting providers can have 400 or more sites on a single server, you can see where that could become a problem. Revo is admittedly a bit heavy on server resources, so you definitely need a decent hosting provider. GoDaddy, Hostgator are not recommended.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 1343 ☆ A M B ☆
                • 2,213 Posts
                Bob and Susan are correct, that just screams overloaded server which is a provider specific problem. The server's bandwidth usage is a poor indication of server load, as the resources being served have a far greater impact on performance. You could have the same server use 500GB of bandwidth, and the performance be radically different (static vs dynamic files). The more processing the server must do the greater risk of performance problems.

                As Susan noted it's not uncommon to see 600-1200 sites on a single shared server with cheap providers, keeping in mind a large portion of sites aren't well optimized. I would suggest trying out another hosting provider as Bob and Susan are recommending. You could alternatively tell hostgator you are having database access issues, and see if they might move you to a less populated server.
                  Patrick | Server Wrangler
                  About Me: Website | Tweets |  MODX Hosting
                  • 47666
                  • 43 Posts
                  I moved the site over to a vps hosting package and I'm still having the problem, but I think i isolated it.

                  When you go to siteName.com it works, but when you go to www.siteName.com it doesn't and I get the error described above.

                  Any ideas why the www. prefix would cause this?

                  You can try it out yourself at
                  http://bestsellinginsurance.com [ed. note: aaron4osu last edited this post 12 years, 1 month ago.]
                    • 3749
                    • 24,544 Posts
                    Both are working for me, but you should really uncomment the part of the .htaccess file that forces the URL to www or non-www.

                    You also need to have this tag in the head section of all templates:

                    <base href="[[++site_url]]" />


                    I'm also guessing that you have some hard-coded URLs in the links on your site. All internal links on the site should be in this form:

                    <a href="[[~12]]">Some Text</a>


                    Replace 12 with the ID of the resource you are linking to.

                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting