Jump to content

[SOLVED] Function not working in include file but works on page...


RIRedinPA

Recommended Posts

I have this function (see below) which when placed on a page works fine, when I place it in a include file I get a fatal error because the function can't be found. Why would it worked if it is hardcoded on the PHP page but not as an include file?

 

function do_query($query, $line) {
  
$client = "Photo Archive"; // Client Name
$email = "email@email.com"; // Email to notify on error
  
$result = @mysql_query($query);
$total = @mysql_num_rows($result);
if (@mysql_error() <> "") {
	echo " <br><font face=\"Verdana\" size=\"1\"><small><b><p align=\"center\">Sorry, there has been an unexpected database error. The webmaster has been informed of this error.</p></b></small></font>";

// Error number

$error_message = "<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" style=\"border: 1px solid bbbbbb;\" bgcolor=\"ffffff\" width=\"80%\" align=\"center\"><tr><td align=\"right\" width=\"25%\"><font face=\"Verdana\" size=\"1\"><small><b>Error Number:</b></small></font></td><td width=\"75%\"><font face=\"Verdana\" size=\"1\"><small>" . @mysql_errno() . "</small></font></td></tr>";
  
// Error Description

$error_message .= "<tr><td align=\"right\"><font face=\"Verdana\" size=\"1\"><small><b>Error Description:</b></small></font></td><td><font face=\"Verdana\" size=\"1\"><small>" . @mysql_error() . "</small></font></td></tr>";
  
// Error Date / Time

$error_message .= "<tr><td align=\"right\"><font face=\"Verdana\" size=\"1\"><small><b>Error Time:</b></small></font></td><td><font face='Verdana' size='1'><small>" . date("H:m:s, jS F, Y") . "</small></font></td></tr>";
  
// Client

$error_message .= "<tr><td align=\"right\"><font face=\"Verdana\" size=\"1\"><small><b>Client:</b></small></font></td><td><font face=\"Verdana\" size=\"1\"><small>" . $client . "</small></font></td></tr>";
  
// Script

$error_message .= "<tr><td align=\"right\"><font face=\"Verdana\" size=\"1\"><small><b>Script:</b></small></font></td><td><font face=\"Verdana\" size=\"1\"><small>" . $_SERVER["SCRIPT_NAME"] . "</small></font></td></tr>";
  
// Line Number

$error_message .= "<tr><td align=\"right\"><font face=\"Verdana\" size=\"1\"><small><b>Line:</b></small></font></td><td><font face=\"Verdana\" size=\"1\"><small>" . $line . "</small></font></td></tr></table>";
  
// SQL

$error_message .= "<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" style=\"border: 1px solid bbbbbb;\" bgcolor=\"ffffff\" width=\"80%\" align=\"center\"><tr><td align=\"right\"><font face=\"Verdana\" size=\"1\"><small><b>Query:</b></small></font></td><td><font face=\"Verdana\" size=\"1\"><small>" . $query . "</small></font></td></tr>";

$error_message .= "<tr><td align=\"right\" valign=\"top\" width=\"25%\"><font face=\"Verdana\" size=\"1\"><small><b>Processes:</b></small></font></td><td><font face=\"Verdana\" size=\"1\"><small>";

$result = @mysql_list_processes();
while ($row = @mysql_fetch_assoc($result)){
	$error_message .= $row["Id"] . " " . $row["Command"] . " " . $row["Time"] . "<br>";
}
@mysql_free_result($result);

$error_message .= "</small></font></td></tr></table>";

$headers = "From: \"MySQL Debug\" <" . $email . ">\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

mail($email, "[MySQL Error] ". $client, $error_message, $headers);
die();
}
if ($_GET["debug"]=="1") {
echo "<div width=\"100%\" style=\"margin: 10px; margin-bottom: 0; padding: 3px; border: 1px solid ff0000; background-color: ffffff; font: 10px verdana; overflow: auto;\">".$query."<p>" . $error_message ."</div><div width=\"100%\" style=\"margin: 10px; margin-top: 0; padding: 3px; border: 1px solid ff0000; background-color: ff0000; font: 10px verdana; color: ffffff; font-weight: bold;\">" . $total . " rows found.</div>";
}
return $result;
}

Link to comment
Share on other sites

Post the code where you've included it.  We don't need to see the function... more the code where you've included it.

 

And you know that inside of included files you need to use <?php & ?> right?  AKA you function when its in an included file must be wrapped by php opening and closing tags.

Link to comment
Share on other sites

This is the page I am calling the include file on. The include is at the bottom of the file, below the closing </html> tag.

 

 

 

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>

<html xmlns='http://www.w3.org/1999/xhtml'>

<head>

<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />

<title>Untitled Document</title>

 

<script language='javascript' src='scriptarama2.js'></script>

</head>

 

<body style='font: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #333333;'>

 

<?php

 

//set up logNumArray

$logNumArray = array();

 

$keysToSearch = $_POST['keysToSearch'];

$keyList = split( chr(32), $keysToSearch);

 

if (count($keyList) < 2) {

$query = "SELECT * FROM photorecord WHERE keywords LIKE '%" . $keyList[0] . "%'";

} else {

for ($q=0; $q<=count($keyList); $q++) {

if ($q == 0) {

$query = "SELECT * FROM photorecord WHERE keywords LIKE '%" . $keyList[$q] . "%'";

 

} else if ($q > 0  && $q < count($keyList)) {

$query .= " OR keywords LIKE '%" . $keyList[$q] . "%'";

}

}

}

 

$query .= " ORDER BY logNum DESC";

//get results

$result = doQuery($query);

$itemCount = mysql_num_rows($result);

 

 

//show results

$i=0;

if ($itemCount > 0) {

while ($itemCount > $i) {

$i++;

$logNum = mysql_result($result,$i-1,'logNum');

$logNumArray[] = $logNum;

}

}

 

 

?>

 

<div id="searchdata" style="position: absolute; top: 50px; left: 100px; z-index: 0">Your search for "<?php echo $keysToSearch; ?>" produced <?php echo $itemCount; ?> result(s)</div>

<div id="resultslayer" style="position: absolute; top: 100px; left: 100px; width: 700px; z-index:0; font: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #333333;">

<?php

//build the thumbnail preview

$tableStuff = "<table cellpadding='7' cellspacing='0' border='0'><tr valign='top'>";

$colCount = 0;

//loop through results

for ($l=0; $l<=count($logNumArray); $l++) {

//skip the last one, it's junk

if ($l < count($logNumArray)) {

 

//set $logNum

$logNum = $logNumArray[$l];

//do stuff with log num

list($width, $height, $type, $attr) = getimagesize('/Volumes/ARTARCHIVE/MerionPhotoArchive/' . $logNum . '/jpeg/' . $logNum . '-1.jpg');

 

 

if ($width > $height) {

$changePercentage = 150/$width;

$newWidth = "150";

$newHeight = $height * $changePercentage; 

} else {

$changePercentage = 150/$height;

$newHeight = "150";

$newWidth = $width * $changePercentage;

}

 

$fileCount = getFileCount($logNum);

$fileSizeArray = getFileSize($logNum, $fileCount);

$fileSizeList = makeFileSizeList($fileSizeArray);

 

//get image details

include('lib/getData.php');

 

$colCount = $colCount + 1;

if ($colCount < 7) {

$tableStuff .= "<td><table><tr valign='top'><td height='150'><img src='/photoarchivethumbs_arc/" . $logNum . "/jpeg/" . $logNum . "-1.jpg' height='" . $newHeight . "' width='" . $newWidth . "' border='0'></td><tr valign='top'><td>Log Number: " . $logNum . "<br>" . $fileCount . " Files</td></tr></table></td>";

} else {

$tableStuff .= "</tr><tr valign='top'><td><table><tr valign='top'><td height='150'><img src='/photoarchivethumbs_arc/" . $logNum . "/jpeg/" . $logNum . "-1.jpg' height='" . $newHeight . "' width='" . $newWidth . "' border='0'></td><tr valign='top'><td>Log Number:" . $logNum . "<br>" . $fileCount . " Files</td></tr></table></td>";

$colCount = 1;

}

}

}

$tableStuff .= "</tr></table>";

echo $tableStuff;

?>

    <div id="footer" style="position: relative; top: 30px; left: 5px;">

        Search Again<p>

            <?php include ("lib/searchForm.html"); ?>

        </div>

</div>

 

<div id="detailslayer" style="position: relative; z-index: 2; background-color: #FFFFFF; visibility: hidden; font: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #333333;"> </div>

<div id="otherimages" style="position: absolute; visibility:hidden; z-index: 2; background-color: #ffffff;"> </div>

<div id="datalayer" style="position: absolute;  z-index: 2; visibility: hidden; font: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #333333; background-color: #FFFFFF;"> </div>

<div id="blacklayer" style="position: absolute; top: 0px;left: 0px;width: 2400px;height: 2400px; background-color: #000000;filter:alpha(opacity=80);-moz-opacity:.80;opacity:.80;visibility: hidden;z-index: 1;"></div>

 

</body>

</html>

 

<?php include "functions.php"; ?>

 

 

Here is what is on the include file: - changed some of the connection stuff but otherwise this is it

 

<?php

function doQuery($query) {

 

/* declare some relevant variables */

$DBhost = "name.name.com";

$DBuser = "web_user";

$DBpass = "*******";

$DBName = "oldphotoarchive";

$table = "photorecord";

 

//connect to db

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select database $DBName");

 

$result = mysql_query($query) or die (mysql_error() . "\nYour request couldn't be procesed.");

return $result;

}

 

 

function getFileCount($logNum) {

 

$fileCount = 0;

$path = "/Volumes/ARTARCHIVE/" . $logNum . "/jpeg/";

 

if (file_exists($path)) {

$handle = opendir($path) or die("Unable to open $path");

while ($file = readdir($handle)) {

  if(stristr($file, $logNum . "-") != FALSE) {

$fileCount = $fileCount + 1;

}

}

 

if ($fileCount > 8) {

$fileCount = 8;

}

}

closedir($handle);

 

return $fileCount;

}

 

 

function getFileSize($logNum, $fileCount) {

$fileSizeArray = array();

for ($i=1; $i<=$fileCount; $i++) {

$fileSizeArray [] = list($width, $height, $type, $attr) = getimagesize("/Volumes/ARTARCHIVE/" . $logNum . "/jpeg/" . $logNum . "-" . $i . ".jpg");

}

 

 

return $fileSizeArray;

}

 

function makeFileSizeList($fileSizeArray) {

$fileSizeList = "";

for ($y=0; $y<=count($fileSizeArray); $y++) {

$fileSizeList = $fileSizeList . $fileSizeArray[$y][0] . "::" . $fileSizeArray[$y][1] . "##";

}

return $fileSizeList;

 

}

 

function cleanUpJunk($thisString) {

$thisString = str_replace("'" ,"\\'" , $thisString);

return $thisString;

}

 

?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.