Hello all.
I've been banging my head against the wall since yesterday trying to solve this problem and, needless to say, it hasn't worked. It just cracked my skull and made a mess on the wall...anyhow....
I have written a script to search through my mySQL database for user-entered keywords. It works perfectly as a stand-alone script, but...
I'm using PHPLIB's templates.inc file for a php/mysql driven site. It mostly works like a charm. When you put a search word into the form an push the button, it is supposed to search the database for the word and return a set of results. The code for my search function lives in the database along with all the other site content.
The problem I am having is with the eval() function. In order to properly execute my php-based search function, I have to include it in the template from the database and, once the template has all it's holes filled, eval() it again to run the search feature.
The error I am getting is as follows:
Parse error: parse error in /home/cust2/usr2049/html/web.php3(237) : eval()'d code on line 366
Below is an excerpt from the search source code. i will clearly mark line 366 (look for '!!!-> LINE 366 in eval()'d code!!!! ').
/ This is the total number of words in the array $search_words/
$search_num = count($search_words);
/ Here we define the $table array. All the tables to be searched should be in here. /
$table = array("main","ilinks","about","fbs","awards","finder","news");
$table_num = count($table);
/
This for loop builds the query to be run on the tables,
then executes the query on each table and returns the results.
The loop code is from here to the end of this file.
/
echo "<h4>Your Search Returned The Following Results for: $search</h4>";
/ This line beginning with 'for' basically says 'Do this for each table' /
for ($i = 0; $i < $table_num; ++$i) {
/* This $statement variable is sufficient if there's only one search word */
$statement = "SELECT tbl, page, title, description FROM $table[$i] WHERE keywords LIKE '%$search_words[0]%' ";
/* This chunk of code adds to $statement if there is more than one search word.
for each occurrence of an additional search word the phrase
'OR keywords LIKE additional-word' is added to $statement */
if ($search_num > 1){
for ($idx = 1; $idx < $search_num; ++$idx){
$statement .= " OR keywords LIKE ";
$statement .= "'%$search_words[$idx]%' ";
}
}
/ This is the MySQL info. "server", "username", "password" /
$db = mysql_pconnect("server", "username", "password");
mysql_select_db("DATABASE", $db);
/ Here is where the query is actually submitted to MySQL for a result.
Notice: it doesn't query the whole DB at once, rather it queries whichever table the for loop is on /
$result = @($statement, $db);
$num_of_rows = @mysql_num_rows($result);
/ This little widget assembles each result and spits it out to the browser.
Each matching row in the table is spit into an array called $row, similar to a CSV file.
$row[0] is the 'table' field, $row[1] is the 'page' field, $row[2] is the 'title' field, etc./
if($num_of_rows > 0) {
while ($row = mysql_fetch_row($result)) {
!!!-> LINE 366 in eval()'d code!!!! echo "<p><a href=\"../../web/$row[0]/$row[1].html\">
$row[2]</a><br>$row[3]<br><font color='#57A275'>www.mbinet.org/web/$row[0]/$row[1].html</font></p>
";
}
}
}
?>
Well, That's about it...the above script works perfectly as its own .php3 file, but bombs when i try to eval() it.
Please, Please, Help me! I'll be so sad that I won't even want Ice Cream if this foobar don't get fixed!
-dolphinsnot