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 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)