Jump to content

php script not rendering


bluethundr

Recommended Posts

hey guys

 

  I have a php script that won't render in firefox. I am using the local apache install on my mac with mysql locally installed.

 

I have error_reporting E_ALL set in my php.ini file. Other scripts that live in the proper apache directory either just work or E_ALL displays the error.

 

I am working with the platypus book from O'Reilly. The script is trying to use templates to populate an html page. I have a templates directory just below the web root on my mac where I put the example.7-3.tpl file.

 

here's the code

 

example.7-2.tpl

 

<!DOCTYPE HTML PUBLIC
                    "-//W3C//DTD HTML 4.01 Transitional//EN"
                    "http://www.w3.org/TR/html401/loose.dtd">
                    
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <title>Customer Details</title>
<body>
<table>
<tr><th>Name<th>Address<th>City<th>State<th>Zipcode
<!-- BEGIN CUSTOMER -->
<tr><td>{FIRSTNAME} {SURNAME}<td>{ADDRESS}
    <td>{CITY}<td>{STATE}<td>{ZIPCODE}
<!-- END CUSTOMER -->
</table>
</body>
</html>

 

And this is the actual code I am trying to get to work.

 

example.7-3.php

<?php
     require_once "/usr/lib/php/HTML/Template/IT.php";
     include "db.inc";
     
     
     // Connect to the MySQL server
     if (!connection = @ mysql_connect($hostname, $username, $password)))
        die("Cannot connect");
        
     if (!(mysql_select_db($databseName, $connection)))
         showerror();
     
     
     // Run the query on the connection
     if (!($result = @ mysql_query ("SELECT * FROM customer LIMIT 50",
                                     $connection)))
        showerror();
        
     // Create a new template, and specify that template files are
     // in the subdirectory "templates"
     $template = new HTML_Template_IT("./templates");
     
     // Load the customer template file
     $template->loadTempltefile("example.7-2.tpl", true, true);
     
     while ($row = mysql_fetch_array($result))
     {
        // Work with the customer block
        $template->setCurrentBlock("CUSTOMER");
        
        
        // Assign the row data to the template placeholders
        $template->setVariable("FIRSTNAME", $row["firstname"]);
        $template->setVariable("SURNAME", $row["surname"]);
        $template->setVariable("ADDRESSS", $row["address"]);
        $template->setVariable("CITY", $row["city"]);
        $template->setVariable("STATE", $row["state"]);
        $template->setVariable("ZIPCODE", $row["zipcode"]);
        
        
        // Parse the current block
        $template->parseCurrentBlock();
        
      }
      
      
      // Output the webpage
      $template->show();
?>

 

 

Thanks!!!

Link to comment
https://forums.phpfreaks.com/topic/181205-php-script-not-rendering/
Share on other sites

Whats the page doing exactly.. what type of Apache install do you have, note a standard Apache install does not come with php built in, though there are some that do like apache2triad (best one in opinion, not sure if they have a mac release though.)..

 

anyway that also said is the server running? Not to familiar with a mac setup and Apache, but.. especially if your not familiar with running an apache server or its your first time.. the server don't always start pain in the ass to configure sometimes...

 

On the flip side of that, if you know what your doing with apache then, whats the page do when you goto the script?

 

 

I'm using PEAR on the mac. mac Apache is running

 

Apache

mazdayasna:5.10.0 bluethundr$ sudo apachectl -S
[Thu Nov 12 00:59:32 2009] [warn] module ssl_module is already loaded, skipping
VirtualHost configuration:
Syntax OK

 

PEAR

mazdayasna:5.10.0 bluethundr$ pear list
Installed packages, channel pear.php.net:
=========================================
Package          Version State
Archive_Tar      1.3.3   stable
Auth_SASL        1.0.3   stable
Console_Getopt   1.2.3   stable
DB               1.7.13  stable
Date             1.4.7   stable
HTML_Template_IT 1.2.1   stable
Mail             1.1.14  stable
Net_SMTP         1.3.3   stable
Net_Socket       1.0.9   stable
PEAR             1.9.0   stable
Structures_Graph 1.0.3   stable
XML_Util         1.2.1   stable

 

This is where IT.php seemed to be hiding on my system. Running Mac OS X 10.6.1 "Snow Leopard".

 

mazdayasna:5.10.0 bluethundr$ locate IT.php
/usr/lib/php/HTML/Template/IT.php

 

 

 

Well depending on your conf file for apache..

 

/usr/lib/php/HTML/Template/IT.php

 

 

This is a bit sticky.. depending on your apache conf settings.. depending on what that book is telling you. Are you tempting to edit a pre-made script or going by the book following the script in there? Or I dunno there's a lot of ifs to this scenario unfortunately.

 

If that is the book method.. then i would say try something like trimming down the directories one by one til one works.. and see if that works

 

/usr/lib/php/HTML/Template/IT.php

/lib/php/HTML/Template/IT.php

/php/HTML/Template/IT.php

/HTML/Template/IT.php

/Template/IT.php

IT.php

 

Unfortunately as i said to many x factors, im not familiar with the book your reading.. so I couldnt evn take a look at the section your looking at.

 

bottom line is from what I have learned from books is that sometimes they are wrong, they teach in the most steril methods possible, fresh installs OS and Server, and what not.. so unfortunately even with that not ever system is alike. I hate to say it like this but I think your in for a lot of toying around to make it work, trial and error style. I wish I could have been more help for you

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.