Jump to content

[SOLVED] running the same code on Mac vs. PC - same PHP version, different result


TheAntipop

Recommended Posts

I've been using a MacBook to develop a small web site, running a PHP server locally to test it out.  Since I would also like to work on the site on my PC occasionally, I installed the WAMP Server package on the PC to facilitate this.  I got the PHP server up and running, and it seems to work fine.  However, when I try to run the exact same code that I run on the Mac on the PC, I get a different result... basically, the site is broken on the PC, and I'm not sure why.

 

OS X comes with both Apache and PHP built in.  I am using PHP version 5.2.6 on both platforms.  However, the Apache version is different on the Mac.  It's the Unix flavor version 2.2.9, while the Apache version on my PC is 2.2.2 (there is no 2.2.9 for Windows).  I'm not sure if the different version of Apache has anything to with the problem.

 

Also, I am not sure if the PHP settings are exactly the same on the PC and Mac.  WAMP has a list of PHP settings that can be checked and unchecked, and I'm wondering if changing some of these would solve the problem.  I'm just not sure which ones to change.

 

Here is what the site is supposed to look like:

 

http://mattmasi.com/mainboots.php

 

When I run it from the local server on the Mac, it looks like this, however, when I run the same code from the PC's server, the page stops right after the introduction, and the Select Artist form is not present (which is obviously the most important part of the page).  At first I thought it was ignoring everything between the PHP tags entirely, but I put an echo statement between the tags and it displayed it in the browser. 

 

I can post the code if needed, but right now I'm just wondering about general differences between running a PHP server on Mac vs. PC and how these might be contributing to my problem.  Any help would be appreciated.

It is likely that the problem is due php configuration differences. You would need to post your code for anyone to be able to see what it might be doing that is configuration specific. Please identify at what point in the code that corresponds to the point in the output where the problem occurs.

It is likely that the problem is due php configuration differences. You would need to post your code for anyone to be able to see what it might be doing that is configuration specific. Please identify at what point in the code that corresponds to the point in the output where the problem occurs.

 

OK, here is the code.  I have removed code irrelevant to my problem (and have commented where this occurs), and I have commented the point at which the problem occurs.

 

<html>
<head>
<!-- Unrelated CSS/header tags removed -->
</head>
<body>
<center>
<img src="antiloss.gif"></center>
<table class = "test2" cellspacing ="1" cellpadding=20 border=1 align="center">
<tr><td>
<!-- Introduction text removed -->
</td></tr>
</table>

<?php
include('mysqltest3.php');
include('ps_pagination.php');

/* The following if statement is not executed when the site is
loaded for the first time, and is not relevant to my problem;
it is included for context */

if(isset($_GET['subgetrecords']) || isset($_GET['artist']))
{
     $sql = "SELECT * from losslessaudio where artist_id = (SELECT id from artists where artist = '". $_GET['artist'] . "')";

     switch ($_GET['sortby'])
     {  
          case "ID":
  	  $sql = $sql . " order by pk";
  	  break;
  
  	  case "Date":
  	  $sql = $sql . " order by date_";
  	  break;
  
  case "City":
  	  $sql = $sql . " order by city";
  	  break;

  	  case "Venue":
  	  $sql = $sql . " order by Venue";
  	  break;

  	  case "Title":
  	  $sql = $sql . " order by Title";
  	  break;

  	  case "Format":
  	  $sql = $sql . " order by Format";
  	  break;
  
  	  default:
          $sql = $sql . " order by date_";
    }
    if ($_GET['order'] == 'desc')
    {
    	$sql = $sql . " DESC";
    }

    $pager = new PS_Pagination($conn,$sql,100,6,$artist);
    $rs = $pager->paginate();
}

/* The problem is occuring in the code that follows. It is supposed
to display a table containing a dropdown menu with the list of artists
pulled from my database and a submit form, but neither the table nor form
are displayed when executed on my PC.

Maybe the mixture of PHP and HTML is causing a problem? Like I said,
the code runs fine on my Mac.  */
?>

<table class = "test3" cellspacing ="1" cellpadding=5 border=1 align="center">
<tr><td>
<form action="mainboots.php?#target" method="GET" font size = "10" >
<table align="center" border="0" cellspacing="0" cellpadding="3">
<?php
$q = "SELECT * FROM artists order by artist";
$result = mysql_query($q, $conn);

echo "<span style=\"font-size: 10pt\">";
echo "<tr><td>Select Artist:</td><td><select name='artist'>";
echo "</span>";
while($dbarray = mysql_fetch_array($result, MYSQL_ASSOC))
{
     echo "<option value= \"". $dbarray['artist']. "\"";
     if ($dbarray['artist'] == str_replace('\\', "", $_GET['artist']))
     {
          echo " selected>" .$dbarray['artist']. "</option>";
     }
     else
     {
          echo ">" . $dbarray['artist']. "</option>";
     }
}
echo mysql_error;
echo "</td>";
echo "<a name='target'>";

?>
<td align="right">
<input type="hidden" name="subgetrecords" value="1">
<input type="hidden" name="sortby" value="Date">
<input type="hidden" name="order" value="asc">
<input type="submit" value="Submit"></td></tr>
</form>
</table>
</td></tr>
</table>

<?php

/* The rest of the code deals with what happens when
the Submit button is clicked, and is not relevant
to my current problem, but has been included for 
context. */

function maketableheader($fields)
{
for ( $i = 0; $i < sizeof($fields); $i++ )
{

	echo "<th align='left' bgcolor=palegreen>";
	echo "<a href=\"mainboots.php?sortby=".
	$fields[$i]. "&artist=". $_GET['artist']. "&order=asc";
	echo "#target\">";
	if ($fields[$i] == 'ID')
	{
		echo "ID #";
	}
	else
	{
		echo $fields[$i];
	}
	echo "</a>";
	if ($_GET['sortby'] == $fields[$i]){
	if ($_GET['order'] == "asc")
	{
		echo " <a href=\"mainboots.php?sortby=".
	$fields[$i]. "&artist=". $_GET['artist']. "&order=desc". "#target\"><img src=\"sortdesc.gif\" style=\"margin-bottom: -2px\" title=\"Reverse Sort Order\"
	border=\"0\"></a>";
	}
	else if ($_GET['order'] == "desc")
	{
		echo " <a href=\"mainboots.php?sortby=".
		$fields[$i]. "&artist=". $_GET['artist']. "&order=asc". "#target\"><img src=\"sortasc.gif\" style=\"margin-bottom: -2px\" title=\"Reverse Sort Order\"
		border=\"0\"></a>";
	}
}
echo "</th>";
}
}

if(isset($_GET['artist'])){

echo "<table class = \"test\" cellspacing =\"1\" cellpadding=5 border=1 align=\"center\">";
echo "<tr><td colspan = '7' bgcolor='khaki' align='center'><b>";
echo $pager->renderHeader();
echo "</b></td></tr>";

$fields = array("ID", "Date", "City", "Venue", "Title", "Format");

maketableheader($fields);
echo "</tr>";

while($row = mysql_fetch_assoc($rs)) {
   echo "<tr><td bgcolor=\"white\">";
   echo "<a href=\"bootnotes.php?location=".$row['pk']. "&artist=". $_GET['artist']. "\" onclick=\"document.cookie='yscroll'+'='+''+1;\" >". $row['pk']."</a>";
   echo "</td><td bgcolor=white>";
   echo $row['Date_'];
   echo "</td><td bgcolor=white>";
   echo $row['City'];
   echo "</td><td bgcolor=white>";
   echo $row['Venue'];
   echo "</td><td bgcolor=white>";
   echo $row['Title'];
   echo "</td><td bgcolor=white>";
   echo $row['format'];
   #echo "</td><td bgcolor=white>";
   echo "</td></tr>";
   }
echo "</table>";
}
echo "<br><span style=\"color:white; font-size: 10pt\"><center>&#169; 2008 Antipopular Productions</center></span>";
echo "</body></html>";

?>

Add error_reporting(E_ALL); ini_set('display_errors', '1'); at the top of your code and see what it says the error is.  I suspect that the MySQL extension is not loaded.

 

Thank you - this revealed the problem!  It was indeed a MySQL issue.  The error was simply "Unknown MySQL Server host."  The PHP file I include that creates the MySQL server connection was pointing to the wrong server address.  Problem solved, thanks again.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.