XAMPP problem - php pages just show code, don't build page

  • cerio
  • Proficient
  • Proficient
  • User avatar
  • Joined: Feb 07, 2004
  • Posts: 263
  • Loc: UK
  • Status: Offline

Post September 27th, 2012, 9:05 pm

Ok, I have no idea where the problem is or how to fix it, as I don't know much about php or sql.

Here are the bits of the three php files that I wonder if the error can be found in. My database in xampp is called esite and the file I installed in it is called esite.sql.zip

I don't know if these pieces of code are helpful but here goes, as I have no idea how to fix...
Quote:

you have an error in your SQL syntax. Check the manual that corresponds to your MySQL server for the right syntax to use near " at line 3


These are the first 7 lines of my index.php file (the error above is displayed when I open it in the browser (localhost/index.php)
Code: [ Select ]
<?php
require_once 'library/config.php';
require_once 'library/category-functions.php';
require_once 'library/product-functions.php';
require_once 'library/cart-functions.php';

$_SESSION['shop_return_url'] = $_SERVER['REQUEST_URI'];
  1. <?php
  2. require_once 'library/config.php';
  3. require_once 'library/category-functions.php';
  4. require_once 'library/product-functions.php';
  5. require_once 'library/cart-functions.php';
  6. $_SESSION['shop_return_url'] = $_SERVER['REQUEST_URI'];


These are the first 23 lines of my config.php file
Code: [ Select ]
<?php
ini_set('display_errors', 'On');
//ob_start("ob_gzhandler");
error_reporting(E_ALL);

// start the session
session_start();

$dbHost = 'localhost';
$dbUser = 'root';
$dbPass = '';
$dbName = 'esite';

// setting up the web root and server root for
// this shopping cart application
$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];

$webRoot = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
$srvRoot = str_replace('library/config.php', '', $thisFile);

define('WEB_ROOT', $webRoot);
define('SRV_ROOT', $srvRoot);
  1. <?php
  2. ini_set('display_errors', 'On');
  3. //ob_start("ob_gzhandler");
  4. error_reporting(E_ALL);
  5. // start the session
  6. session_start();
  7. $dbHost = 'localhost';
  8. $dbUser = 'root';
  9. $dbPass = '';
  10. $dbName = 'esite';
  11. // setting up the web root and server root for
  12. // this shopping cart application
  13. $thisFile = str_replace('\\', '/', __FILE__);
  14. $docRoot = $_SERVER['DOCUMENT_ROOT'];
  15. $webRoot = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
  16. $srvRoot = str_replace('library/config.php', '', $thisFile);
  17. define('WEB_ROOT', $webRoot);
  18. define('SRV_ROOT', $srvRoot);


These are the first 19 lines of my database.php file
Code: [ Select ]
<?php
require_once 'config.php';

$dbConn = mysql_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error());
mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error());

function dbQuery($sql)
{
    $result = mysql_query($sql) or die(mysql_error());
    
    return $result;
}

function dbAffectedRows()
{
    global $dbConn;
    
    return mysql_affected_rows($dbConn);
}
  1. <?php
  2. require_once 'config.php';
  3. $dbConn = mysql_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error());
  4. mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error());
  5. function dbQuery($sql)
  6. {
  7.     $result = mysql_query($sql) or die(mysql_error());
  8.     
  9.     return $result;
  10. }
  11. function dbAffectedRows()
  12. {
  13.     global $dbConn;
  14.     
  15.     return mysql_affected_rows($dbConn);
  16. }


I made no changes to security in xampp.

I hope that information is enlightening enough. If anyone can work out the problem from these, I'd be very grateful.

Regards,
Cerio
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post September 27th, 2012, 9:05 pm

  • Liamw411
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Oct 18, 2012
  • Posts: 5
  • Status: Offline

Post October 18th, 2012, 7:11 am

Hi, don't know if you've managed to sort this but if you installed xampp correctly it should render your php files, sounds to me like you are trying to access the files directly and not via the server. Try http://127.0.0.1 or http://localhost/
  • cerio
  • Proficient
  • Proficient
  • User avatar
  • Joined: Feb 07, 2004
  • Posts: 263
  • Loc: UK
  • Status: Offline

Post October 21st, 2012, 12:02 am

Thank you so much for your reply Liamw411. I did use http://localhost/.

Having had to leave it all for some months, I went back and tried again, just before I received your email, and oddly enough, it worked sort of (now have no idea what was wrong before but before I tried again, I replaced some of my site files with back-up ones and the error must have been on one that was overwritten by that) but there's a new problem. :?

I have noticed something puzzling; a section that works fine when the site is uploaded to my web host and online, does not display properly when viewed via XAMPP / localhost. The rest of the page displays perfectly and, as far as I've noticed so far, the rest of the site does too but, on every page that provides details of my items, there is this new problem, although there is no difference in code between the one online at my webhost's and the one viewed locally via XAMPP, so I don't understand why they display differently.

I can show you what I mean. The first photo is how it should look and how it is when actually uploaded and online, the second photo shows the problem when viewed locally on my computer, via XAMPP.
Below the photos is the code that creates that section.

When uploaded and online...


Image



When viewed locally via XAMPP (the NEW icons are explained below the picture)...

Image

Note - the correctly displayed photo (top one) does not [and should not] show a 'NEW' icon at all, because that item was added to the database more than 4 weeks ago. If it had been added within the last 4 weeks, it would show a little icon saying 'NEW', like in the picture below, the icon colour would depend on which week of those first 4 weeks it was at. The meaning of these icons and of their colours is explained elsewhere on the site.

Image


Below, you can see the code for that section of the page (exactly the same code is used in both the correctly displayed and the incorrectly displayed examples of the page). Note that the last part of the code ($pd_description etc) is not shown in the photos, as I cropped them to show just the faulty bit, but that bit of code is displaying correctly.

Code: [ Select ]
<?php
if (!defined('WEB_ROOT')) {
    exit;
}

$product = getProductDetail($pdId, $catId);
$shippingRow=$product;
// $pd_name, $pd_price, $pd_description, $pd_image, $cart_url
extract($product);
?>


<table bgcolor="FFFFFF" width="95%" border="0" cellspacing="0" cellpadding="3">
<tr> <a name="up">
 <td><img src="<?php echo $pd_image_path; ?>" width="286" height="341" border="0" alt="<?php echo $pd_name; ?>"></td>
 <td width="100%" valign="top">
<strong><?php echo $pd_name; ?></strong><br>
<?
//$today=date("Y-m-d");
$compareDate1=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-28,date("Y"))); // -28 = 4 weeks
$compareDate2=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-21,date("Y"))); // -21 = 3 weeks
$compareDate3=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-14,date("Y"))); // -21 = 3 weeks
$compareDate4=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-7,date("Y"))); // -21 = 3 weeks

// is it newer than 4 weeks?
if ($pd_date > $compareDate4)
  {echo "<img src='images/new1.gif' alt='new' /><br />";
  }
        // is it newer than 3 weeks?
elseif ($pd_date > $compareDate3)
  {echo "<img src='images/new2.gif' alt='new' /><br />";
  }
// is it newer than 2 weeks?  
elseif ($pd_date > $compareDate2)
  {echo "<img src='images/new3.gif' alt='new' /><br />";
  }
// is it newer than 1 week?  
elseif ( $pd_date > $compareDate1)
  {echo "<img src='images/new4.gif' alt='new' /><br />";
  }


?>
<font color="red"><strong>Item code:</strong></font> <? echo $pd_code;?><br />
<br><font color="red"><strong>Price:</strong></font> <?php echo displayAmount($pd_price); ?><br />
<br /><font color="red"><strong>Available:</strong></font> <? echo $pd_qty;?>
<br /><br /><font color="red"><strong>Shipping:</strong></font>

<br /><strong>UK:</strong></font> &pound;<?echo $pd_price_uk;?><br />
<strong>Europe:</strong> &pound;<?=$pd_price_eu?><br /><strong>Rest of World:</strong> &pound;<?=$pd_price_us?>
<br /><font color="red"><strong>Delivery OUTSIDE UK:</font></strong> buyer<strong> MUST </strong>also<br />purchase Mail Insurance<br />from the site's <a href="http://wafuku.co.uk/index.php?c=2083">Mail Insurance</a> section</font>
<br /><br />

<?php
// if still have this product in stock
// show the 'Add to cart' button
if ($pd_qty > 0) {
?>

<input type="button" name="btnAddToCart" value="Add To Cart &gt;" onClick="window.location.href='<?php echo $cart_url; ?>';" class="addToCartButton">
<?php
} else {
    echo "<strong><font color='#FF0000'>Sold</font></strong>";
}

?>
<br /><br /> Full postage &amp; insurance<br />details on Postage Page<br />

 </td>
</tr>
<tr align="left">
 <td colspan="2"><?php echo $pd_description; ?></td>
</tr>
</table>
  1. <?php
  2. if (!defined('WEB_ROOT')) {
  3.     exit;
  4. }
  5. $product = getProductDetail($pdId, $catId);
  6. $shippingRow=$product;
  7. // $pd_name, $pd_price, $pd_description, $pd_image, $cart_url
  8. extract($product);
  9. ?>
  10. <table bgcolor="FFFFFF" width="95%" border="0" cellspacing="0" cellpadding="3">
  11. <tr> <a name="up">
  12.  <td><img src="<?php echo $pd_image_path; ?>" width="286" height="341" border="0" alt="<?php echo $pd_name; ?>"></td>
  13.  <td width="100%" valign="top">
  14. <strong><?php echo $pd_name; ?></strong><br>
  15. <?
  16. //$today=date("Y-m-d");
  17. $compareDate1=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-28,date("Y"))); // -28 = 4 weeks
  18. $compareDate2=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-21,date("Y"))); // -21 = 3 weeks
  19. $compareDate3=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-14,date("Y"))); // -21 = 3 weeks
  20. $compareDate4=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-7,date("Y"))); // -21 = 3 weeks
  21. // is it newer than 4 weeks?
  22. if ($pd_date > $compareDate4)
  23.   {echo "<img src='images/new1.gif' alt='new' /><br />";
  24.   }
  25.         // is it newer than 3 weeks?
  26. elseif ($pd_date > $compareDate3)
  27.   {echo "<img src='images/new2.gif' alt='new' /><br />";
  28.   }
  29. // is it newer than 2 weeks?  
  30. elseif ($pd_date > $compareDate2)
  31.   {echo "<img src='images/new3.gif' alt='new' /><br />";
  32.   }
  33. // is it newer than 1 week?  
  34. elseif ( $pd_date > $compareDate1)
  35.   {echo "<img src='images/new4.gif' alt='new' /><br />";
  36.   }
  37. ?>
  38. <font color="red"><strong>Item code:</strong></font> <? echo $pd_code;?><br />
  39. <br><font color="red"><strong>Price:</strong></font> <?php echo displayAmount($pd_price); ?><br />
  40. <br /><font color="red"><strong>Available:</strong></font> <? echo $pd_qty;?>
  41. <br /><br /><font color="red"><strong>Shipping:</strong></font>
  42. <br /><strong>UK:</strong></font> &pound;<?echo $pd_price_uk;?><br />
  43. <strong>Europe:</strong> &pound;<?=$pd_price_eu?><br /><strong>Rest of World:</strong> &pound;<?=$pd_price_us?>
  44. <br /><font color="red"><strong>Delivery OUTSIDE UK:</font></strong> buyer<strong> MUST </strong>also<br />purchase Mail Insurance<br />from the site's <a href="http://wafuku.co.uk/index.php?c=2083">Mail Insurance</a> section</font>
  45. <br /><br />
  46. <?php
  47. // if still have this product in stock
  48. // show the 'Add to cart' button
  49. if ($pd_qty > 0) {
  50. ?>
  51. <input type="button" name="btnAddToCart" value="Add To Cart &gt;" onClick="window.location.href='<?php echo $cart_url; ?>';" class="addToCartButton">
  52. <?php
  53. } else {
  54.     echo "<strong><font color='#FF0000'>Sold</font></strong>";
  55. }
  56. ?>
  57. <br /><br /> Full postage &amp; insurance<br />details on Postage Page<br />
  58.  </td>
  59. </tr>
  60. <tr align="left">
  61.  <td colspan="2"><?php echo $pd_description; ?></td>
  62. </tr>
  63. </table>


I would be very grateful if anyone could tell me why they display differently.

Regards,
Cerio
  • Liamw411
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Oct 18, 2012
  • Posts: 5
  • Status: Offline

Post October 21st, 2012, 4:36 am

If it is the same code you are using on both, the issue may be that you have different versions of php on your server and your local machine.
Make a php info page and check to see if the versions are identical?.
  • cerio
  • Proficient
  • Proficient
  • User avatar
  • Joined: Feb 07, 2004
  • Posts: 263
  • Loc: UK
  • Status: Offline

Post October 21st, 2012, 5:37 am

Ah. Thank you.
My web host has php 5.3.3 and XAMPP has 5.4.4. So it is the 5.4.4 that it is not rendering properly on.
Anything I can do to ensure it works on both (bearing in mind that I really know nothing about php code)?
  • Liamw411
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Oct 18, 2012
  • Posts: 5
  • Status: Offline

Post October 21st, 2012, 7:17 am

Easiest way to fix would be to copy all files and databases, uninstall xampp and download and install a version that has php 5.3.3. And then replace files + databases.
  • cerio
  • Proficient
  • Proficient
  • User avatar
  • Joined: Feb 07, 2004
  • Posts: 263
  • Loc: UK
  • Status: Offline

Post October 21st, 2012, 2:06 pm

Thank you, Liamw411. That will sort things out for me while I work on it, so I may do that.

I wonder, however, if my web host and others may all start using php 5.4.4 sometime, causing the problem to eventually resurface online. Perhaps, to make it future-proof, I need to find a way to fix the problem of how it renders in 5.4.4.

Regards,
Cerio
  • dickot
  • Born
  • Born
  • No Avatar
  • Joined: Jan 03, 2013
  • Posts: 1
  • Status: Offline

Post January 3rd, 2013, 9:39 am

I found myself in exactly the same situation.
I dont know how far you got but check your php.ini file and look for "short_open_tag".
If you have the php open tag "<?" anywhere you will need to set that directive to "On".
Try changing it and re-starting Apache, then see how the page loads.

Post Information

  • Total Posts in this topic: 23 posts
  • Users browsing this forum: No registered users and 303 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.