Link to home
Start Free TrialLog in
Avatar of Pete Winter
Pete WinterFlag for United Kingdom of Great Britain and Northern Ireland

asked on

500 Internal Server Error within Wordpress

I have just moved the website in the below link to a new server:

http://46.32.231.136/~themarbl/get-a-free-quote/

The form on the above link should load content from a mysql database.

If you look on the console on this page you see this error:

Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://46.32.231.136/~themarbl/wp-content/themes/dt_delicate/ajax.php

The ajax.php file does exist. Any idea why I would be getting this error?

This is the original working url if you want to compare: http://www.themarblegroup.co.uk/get-a-free-quote/
SOLUTION
Avatar of Patrick Bogers
Patrick Bogers
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pete Winter

ASKER

Thanks, but even if I can the ajax.php file code to simply...

<?php echo "hello"; ?>

I still get the same error?
I meant...

Thanks, but even if I change the ajax.php file code to simply...

<?php echo "hello"; ?>

I still get the same error?
Are you sure you are editing the right file
/~themarbl/wp-content/themes/dt_delicate/ajax.php
Actually your main page is returning a 500 error code even though it is loading.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes. I just tried something else...

Two very basic files with the same code below, but different file extensions...

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>

<body>
test
</body>
</html>

Open in new window


HTML: http://46.32.231.136/~themarbl/wp-content/themes/dt_delicate/test.html

PHP: http://46.32.231.136/~themarbl/wp-content/themes/dt_delicate/test.php

Why does the php file give an error?
Can you post a phpinfo() and the permissions on the test.php file?
The php file works fine.
Try disabling all your plugins, it's possible one them is evaluating some code causing the error
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks the permission solved the folder test.php file issue. Now just looking into the database connection.
This is the code for the ajax.php file:

<?php

require_once ("marblestore_db.php");

//require_once ("ini.php");

//$_db = new mySqldb ( _DBHOST, _DBUSER, _DBPASS, _DBNAME ); //mySQl DB Instance for Sims DB





$content = '';

if(isset($_REQUEST['action'])){

 //open the data base

 $ms_db = new mysqli(MARBLESTORE_DBHOST, MARBLESTORE_DBUSER, MARBLESTORE_DBPASS, MARBLESTORE_DBNAME);

 if ($ms_db->connect_error) {

    die('Connect Error (' . $ms_db->connect_errno . ') '

            . $ms_db->connect_error);

 }

 switch($_REQUEST['action']){

 case 'send_email':

  //first check the captcha

  $captcha_prefix =$_REQUEST['captcha_prefix'];

  $captcha_value = strtoupper($_REQUEST['captcha_value']);

  $captcha_img=dirname(dirname(dirname(__FILE__)))."/plugins/really-simple-captcha/tmp/$captcha_prefix.png";

  $file=dirname(dirname(dirname(__FILE__)))."/plugins/really-simple-captcha/tmp/$captcha_prefix.txt";

  if ( is_readable( $file ) && ( $code = file_get_contents( $file ) ) ) {

   $code = explode( '|', $code, 2 );

   $salt = $code[0];

   $hash = $code[1];

   if ( hash_hmac( 'md5', $captcha_value, $salt ) !== $hash ){

    $data="Incorrect security code";

    $content=json_encode($data);

    break;

   }

  } else {

   $data="Unknown error";

   $content=json_encode($data);

   break;

  }

  // $data="Incorrect security code ".$_REQUEST['captcha_prefix']." ".$_REQUEST['captcha_value'];



  $to      = $_REQUEST['email'];

  $name    = $_REQUEST['name'];

  $phone   = $_REQUEST['phone'];

  $brand   = $_REQUEST['brand'];

  $location = $_REQUEST['address'];

  $info     = $_REQUEST['info'];

  $thickness = $_REQUEST['thickness'];

  $product = $_REQUEST['product'];

  $style   = $_REQUEST['style'];

  $sink    = $_REQUEST['sink'];

  $grooves = $_REQUEST['grooves'];

  $hob     = $_REQUEST['hob'];

  $tab     = $_REQUEST['tab'];

  $plug    = $_REQUEST['plug'];

  $fitting = $_REQUEST['fitting'];

  $templating= $_REQUEST['templating'];

  $price    = $_REQUEST['price'];

  $vat    = $_REQUEST['vat'];

  $total    = $_REQUEST['total'];

  $subject = 'Quote Requested via themarblegroup.co.uk';

  $message = "Quote Requested 

Customer: $name

Email:$to

Telephone: $phone

Location: $location

   

Quote Requested $product ($brand) $thickness for following items and services:



Worktop pieces sizes:\r\n";

for($i=0;$i<count($_REQUEST['wtl']);$i++)

 $message.="  ".$_REQUEST['wtl'][$i]." [mm] x ".$_REQUEST['wtr'][$i]." [mm] \r\n";

$message.="Upstands/Splashback pieces sizes:";

if(count($_REQUEST['usl'])==0)

 $message.= " 0\r\n";

else

 $message.= " \r\n";

for($i=0;$i<count($_REQUEST['usl']);$i++)

 $message.= "  ".$_REQUEST['usl'][$i]." [mm] x ".$_REQUEST['usr'][$i]." [mm] \r\n";

$message.="Number of cout-outs of $style sink: $sink \r\n";

$message.="Number of sets of drainer grooves: $grooves \r\n";

$message.="Number of cut-outs for a hob: $hob \r\n";

$message.="Number of tab holes: $tab \r\n";

$message.="Number of plug holes: $plug \r\n\r\n";

if($fitting==1)

 $message.="Fitting: [YES] \r\n";

else

 $message.="Fitting: [NO] \r\n";

if($templating==1)

 $message.="Templating [YES]\r\n";

else

 $message.="Templating [NO]\r\n";

if($info!='')

 $message.="User Message:\r\n $info \r\n";

$message.="\r\n Price Ex VAT: $price GBP \r\n";

$message.=" VAT: $vat GBP \r\n";

$message.=" Total Price: $total GBP \r\n";

$headers = 'From: info@themarblegroup.co.uk' . "\r\n" .

    'Cc: info@themarblegroup.co.uk' . "\r\n";

    'Reply-To: info@themarblegroup.co.uk' . "\r\n" .

    'X-Mailer: PHP/' . phpversion();

  if(mail($to, $subject, $message, $headers))

   $data='Your quote was sent';

  else

   $data='Error, try again';

  $content=json_encode($data);

  break;

 case 'brandnames':

  $result=$ms_db->query("select id,value from areas where areaname='brandname' order by value");

  while($row = $result->fetch_assoc())

   $content.='<option class="marble_selected_brand" value='.$row['id'].'>'.$row['value'].'</option>';

  break;

 case 'products':

  if(isset($_REQUEST['brand'])){

   $var=$ms_db->real_escape_string('-'.$_REQUEST['brand'].'-');

   $result=$ms_db->query("select id,name from product where brand like '$var' order by name");

   $selected=false;

   while($row = $result->fetch_assoc())

    if(!$selected){

     $content.='<option selected class="marble_selected_product" value='.$row['id'].'>'.$row['name'].'</option>';

     $selected=true;

    } 

    else

     $content.='<option class="marble_selected_product" value='.$row['id'].'>'.$row['name'].'</option>';

  }

  break;

 case 'prices':

  if(isset($_REQUEST['id'])&&isset($_REQUEST['thickness'])&&isset($_REQUEST['style'])){

   $id=$ms_db->real_escape_string($_REQUEST['id']);

   $thickness=$ms_db->real_escape_string($_REQUEST['thickness']);

   $style=$ms_db->real_escape_string($_REQUEST['style']);

   // query price

   $result=$ms_db->query("select price from price where pricegroup='$id' AND thickness='$thickness'");

   $out = $result->fetch_assoc();

   $data['price']=$out['price'];

   // query unit prices

   $queries['splashback']=1;

   $queries['style']=$style;

   $queries['grooves']=31;

   $queries['hob']=4;

   $queries['tab']=5;

   $queries['plug']=25;

   $queries['fitting']=7;

   $queries['templating']=6;

   

   $queries['polishedsink']=2;   

   $queries['angles']=29;

   $queries['curves']=30;

   $queries['hobbar']=28;

   $queries['hobcutout']=26;

   $queries['recesseddrainer']=32;

   $queries['choppingboard']=27;

   $queries['worktopcleaning']=33;

   

   $queries['dblpencil']=11;

   $queries['singlepencil']=12;

   $queries['dblchamfer']=13;

   $queries['singlechamfer']=14;

   $queries['cove']=10;

   $queries['halfbullnose']=19;

   $queries['a20birdsbak']=16;

   $queries['a20flat']=17;

   $queries['irishwaterfall']=18;

   $queries['mitrededge']=15;

   $queries['ogee']=22;

   $queries['fullbullnose']=23;

   $queries['dupontedge']=24;

   $queries['ogee20bullnose']=21;

   $queries['ogee30bullnose']=20;

   

   foreach($queries as $key=>$value){

    $result=$ms_db->query("select unitprice from service where id='$value'");

    $out = $result->fetch_assoc();

    $data[$key]=$out['unitprice'];

   }

   // query mandatory service

   $queries=array();

   $queries['fitting']=7;

   $queries['templating']=6;

   $queries['vat']=8;

   foreach($queries as $key=>$value){

    $result=$ms_db->query("select price from mandatory_service where id='$value'");

    $out = $result->fetch_assoc();

    $data[$key]=$out['price'];

   }

   $content=json_encode($data);

  }

  break;

 case 'product':

  if(isset($_REQUEST['id'])){

   $var=$ms_db->real_escape_string($_REQUEST['id']);

   $result=$ms_db->query("select id,price,thicknesses,finishings,image from product where id='$var'");

   $row = $result->fetch_assoc();

   $data['id']=$row['id'];

   $data['price']=$row['price'];

   $data['image']=$row['image'];

   //get names for thickness

   $thicknesses=explode('-',$row['thicknesses']);

   foreach($thicknesses as $thickness)

    if($thickness!=''){

     $data['thickness_id'][]=$thickness;

     $result=$ms_db->query("select value from areas where id='$thickness'");

     if($out = $result->fetch_assoc())

     	$data['thickness_value'][]=$out['value'];

    }

   $finishings=explode('-',$row['finishings']);

   foreach($finishings as $finishing)

    if($finishing!=''){

     $data['finishing_id'][]=$finishing;

     $result=$ms_db->query("select value from areas where id='$finishing'");

     $out = $result->fetch_assoc();

     $data['finishing_value'][]=$out['value'];

    }

   $content=json_encode($data);

  }

  break;

}

 $ms_db->close();

}

echo $content;

?>

Open in new window


and this is the marblestore_db.php file with the database details removed...

<?php

/**

 * database settings 

 *

 */

 //ini_set('display_errors','On');

//error_reporting(E_ALL);



define ( "MARBLESTORE_DBHOST", "localhost" );

define ( "MARBLESTORE_DBUSER", "xxx" );

define ( "MARBLESTORE_DBPASS", "xxx" );

define ( "MARBLESTORE_DBNAME", "xxx" );

Open in new window


I also tested the data base with the code below and it was fine.

$server   = "localhost";
$database = "xxx";
$username = "xxx";
$password = "xxx";

$mysqlConnection = mysql_connect($server, $username, $password);
if (!$mysqlConnection)
{
  echo "Please try later.";
}
else
{
mysql_select_db($database, $mysqlConnection);
echo "it works";
}

Open in new window


Any idea what I am not seeing the data on the page below?

http://46.32.231.136/~themarbl/get-a-free-quote/
Thanks for your help with the permissions. The issue with the database connect was that I needed to install MySQLi.