In a bit of code I'm doing, I'm trying to read a file and then replace parts of it, as is done in many Perl scripts: eg ##MESSAGE## is replaced by $message
I can't open the file. When I try I get the following errors:
Warning: Division by zero in /web/sites/31/reywob/www.narrowgauge.f2s.com/cgi-bin/postcard/postcard.php on line 10
Warning: Division by zero in /web/sites/31/reywob/www.narrowgauge.f2s.com/cgi-bin/postcard/postcard.php on line 10
Warning: Division by zero in /web/sites/31/reywob/www.narrowgauge.f2s.com/cgi-bin/postcard/postcard.php on line 10
Warning: Division by zero in /web/sites/31/reywob/www.narrowgauge.f2s.com/cgi-bin/postcard/postcard.php on line 10
Warning: Division by zero in /web/sites/31/reywob/www.narrowgauge.f2s.com/cgi-bin/postcard/postcard.php on line 10
Warning: Division by zero in /web/sites/31/reywob/www.narrowgauge.f2s.com/cgi-bin/postcard/postcard.php on line 10
Parse error: parse error in /web/sites/31/reywob/www.narrowgauge.f2s.com/cgi-bin/postcard/postcard.php on line 10
The code is:
<?php
include ("include/db_setup.php");
include ("include/postcard_setup.php");
$query = ("SELECT * FROM postcards where id=".$id.");
$result = pg_exec($conn,$query); $result_countt=0;
$postcard = @pg_fetch_array($result,$result_countt++);
$file = fopen("/web/sites/31/reywob/www.narrowgauge.f2s.com/cgi-bin/postcard/include/postcard.tpl","r");
/
if (!$file = fopen ("include/postcard.tpl", "r")) {
echo("Sorry, could not open file.");
}
/
$str = fpassthru($file);
for ($i = 0; $i < pg_numfields($result); $i++) {
$pat = "[".strtoupper(pg_fieldname($result, $i))."]";
$repl = $postcard[".pg_fieldname($result, $i)."];
ereg_replace ($pat, $repl, $str);
}
echo ($str);
mail ("$from_email", "$cardreceived_subject", "$cardreceived", "From: $to_email");
?>
Can anyone see the problem, or any other problems????
TIA,
Peter.