Page 1 of 1
Search is Broken! :(
Posted: Wed Feb 12, 2003 8:27 pm
by Splitfyre
Good Evening Guys,
I have a question regarding my search.php file. For some reason it now gives the following error when I try to access my search page:
Code: Select all
Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /home/virtual/site3/fst/var/www/html/search.php on line 30
What's up with this? Any help would be gladly appreciated.
Posted: Wed Feb 12, 2003 8:44 pm
by redcircle
look for missplaced or missing { or } chars.
Parse error: parse error in /home/virtual/site3/fst/var/www/
Posted: Thu Feb 13, 2003 12:58 am
by Splitfyre
Nope that didn't do it
Still getting it:
Parse error: parse error in /home/virtual/site3/fst/var/www/html/search.php on line 30
//------------------------------------------------------------------------------------------------
function ViewForm()
{
T_Variable global extract($GLOBALS);
//------------------------------------------------------------------------------------------------
Line 30 Is:
T_Variable global extract($GLOBALS);
I now just get Parse Error as seen in Subject
Posted: Thu Feb 13, 2003 2:01 am
by twigletmac
PHP error messages can be a bit confusing in that when it says missing T_variable it means it thinks that there should be a variable on that line in order for it to continue parsing the file:
http://www.php.net/manual/en/tokens.php
Maybe something like this will work:
Code: Select all
function ViewForm()
{
global $GLOBALS;
extract($GLOBALS);
It probably doesn't like you trying to apply a function to the variable you are trying to declare global.
Mac
Posted: Thu Feb 13, 2003 10:25 am
by Splitfyre
After applying that snippet of code the page won't load at all.
Posted: Thu Feb 13, 2003 10:28 am
by aybra
did you add a closing }??
twigs dosnt have one..
Posted: Thu Feb 13, 2003 11:03 am
by Splitfyre
Where should it be added?
I have a ton of experience in coding in Crystal syntax and Basic syntax so I assume it would be on the next line. Let me know what you think.
Posted: Thu Feb 13, 2003 11:14 am
by aybra
put it at the end of the function.
I'm assuming yes, next line
Posted: Thu Feb 13, 2003 11:23 am
by BigE
errr.... ok, first of all, $GLOBALS is a super global, so forget about making it global inside the function because its already avalible. Second, if you just want all of the variables avalible inside the function, just reffer to them inside of the $GLOBALS array. If you extract() $GLOBALS your going have a headache I think. $GLOBALS holds EVERYTHING. Thats including _GET, _POST, _COOKIES... everything. Just food for thought.
Search Code
Posted: Thu Feb 13, 2003 3:36 pm
by Splitfyre
didn't work
Here's the code.. let me know your thoughts on how I can resolve this error...

Now I get...
Parse error: parse error in /home/virtual/site3/fst/var/www/html/search.php on line 158
This is this line here:
The entire code for the search page as seen below...
Code: Select all
<? // php2php (vbscript) converted
?>
<? $varSection="search"; ?>
<!--#include file="./db_data/ssi_data/header.php"-->
<!--#include file="./manager/ssi-data/variables.shtml"-->
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border: 1px solid #242458"><tr><td width="100%" height="20" bgcolor="#8080a6"><font color="#FFFFFF"><b>
<center>Futurelooks.com Site Search</center>
</b></font></td></tr></table>
<?
switch ($HTTP_GET_VARSї"view"])
{
case "form":
ViewForm();
break;
case "results":
ViewForm();
break;
case "browse":
ViewBrowse();
break;
default:
ViewForm();
break;
}
//------------------------------------------------------------------------------------------------
function ViewForm()
{
global $GLOBALS;
extract($GLOBALS);
}
//------------------------------------------------------------------------------------------------
?>
<br><b>Advanced Search</b><form method="POST" action="/search.php?view=results">
Search For: <input type="text" size="25" name="string">
<input type="reset" name="reset" value="Reset" style="font-size: 10pt; font-family: Tahoma"> <input type="submit" name="search" value="Search" style="font-size: 10pt; font-family: Tahoma">
</form>
<?
if ($HTTP_GET_VARSї"view"]=="results")
{
$SearchString=$HTTP_POST_VARSї"string"];
if ($SearchString=="")
{
}
else
{
// $Connect is of type "ADODB.Connection"
$Connect=mysql_connect("localhost","","");
mysql_select_db("",$Connect);
$ConstArticlesDBLocation;
$Query="SELECT * FROM Articles WHERE ((Body) LIKE '%".$SearchString."%') AND Posted = 1 ORDER BY Date DESC";
$Read_query=mysql_query(($Query),$Connect);
$Read=mysql_fetch_array($Read_query);
if (($Read==0))
{
$ArticleResults=0;
}
else
{
$ArticleResults=0;
while(!(($Read==0)))
{
$ArticleResults=$ArticleResults+1;
$Read=mysql_fetch_array($Read_query);
}
}
mysql_close($Connect);
}
?>
<br>
<? if ($SearchString=="")
{
?>
<b>Search Error!</b>
<? }
else
{
?>
<b>Search Results: "<? echo $SearchString; ?>"</b>
<? } ?>
<br>
<? if ($SearchString=="")
{
?>
You must enter a search string.
<? }
else
{
?>
<? if ($ArticleResults==0)
{
?>
No results found matching the string "<? echo $SearchString; ?>".
<? } ?>
<? if ($ArticleResults!=0)
{
?>
<? echo $ArticleResults; ?> result(s) found in Articles matching your string.
<? } ?>
<? } ?>
<? if ($SearchString=="")
{
?>
<? }
else
{
?>
<? if ($ArticleResults!=0)
{
?>
<a href="/search.php?view=browse&string=<? echo rawurlencode($SearchString); ?>&results=<? echo $ArticleResults; ?>§ion=articles&page=1">Browse Results</a><br>
<? } ?>
<? } ?>
<?
}
else
{
}
?>
<br><br>
<b>Search Tips and Advice</b>
<br>
Keep your search specific yet short in length, it is
better to return a few extra, non-related results rather than none at all.
<br><br>
Generalize search phrases into a few words. For example, use "age of
empires" rather than "expansions for age of empires".
<br><br>
Keep in mind that our search is not sensitive to the case you use. For example, "3dfx" would
return the same results as "3DFX".
<br><br>
If browsing results within our articles, read the result description to determine whether or not it is what you
are looking for.
<br><br>
Select the categories you would like to search in before beginning your search, the results will not only load faster but be more
accurate.
<?
return $function_ret;
}
//------------------------------------------------------------------------------------------------
function ViewBrowse()
{
global extract($GLOBALS);
//------------------------------------------------------------------------------------------------
$SearchString=$HTTP_GET_VARSї"string"];
$ResultsPerPage=10;
$OnPage=intval($HTTP_GET_VARSї"page"]);
$TotalResults=intval($HTTP_GET_VARSї"results"]);
?>
<br><b>Advanced Search</b><form method="POST" action="/search.php?view=results">
Search For: <input type="text" size="25" name="string">
<input type="reset" name="reset" value="Reset" style="font-size: 10pt; font-family: Tahoma"> <input type="submit" name="search" value="Search" style="font-size: 10pt; font-family: Tahoma">
</form>
<br>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<b>Search Results: "<? echo $SearchString; ?>"</b>
</td>
</tr>
</table>
<br>
<?
// $Connect is of type "ADODB.Connection"
$Connect=mysql_connect("localhost","","");
mysql_select_db("",$Connect);
$ConstArticlesDBLocation;
$Query="SELECT * FROM Articles WHERE ((Body) LIKE '%".$SearchString."%') AND Posted = 1 ORDER BY Date DESC";
$Read_query=mysql_query(($Query),$Connect);
$Read=mysql_fetch_array($Read_query);
if (($Read==0))
{
}
else
{
$LoopNum=0;
while(!($LoopNum==$ResultsPerPage*($OnPage-1)))
{
$Read=mysql_fetch_array($Read_query);
$LoopNum=$LoopNum+1;
}
$LoopNum=0;
while(!($LoopNum==$ResultsPerPage || ($Read==0)))
{
$LoopNum=$LoopNum+1;
?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" style="border-style-top: solid; border-width-top: 1px; border-style-bottom: solid; border-width-bottom: 1px">
<small><? echo $Readї"Section"]." ".$Readї"Type"]; ?>: </small><b><? echo $Readї"Title"]; ?> (Page <? echo $Readї"PageNumber"]; ?> of <? echo $Readї"PageTotal"]; ?>)</b><small> on <? echo $Readї"Date"]; ?></small>
</td>
</tr>
<tr>
<td width="100%" style="padding: 5px">
<? echo $Readї"Description"]; ?>
<br>
<div align="right"><a href="/display.php?i=<? echo $Readї"ID"]; ?>&p=<? echo $Readї"PageNumber"]; ?>">Check It Out</a></div>
</td>
</tr>
</table>
<small>
<?
if ($LoopNum!=$ResultsPerPage)
{
print "<hr color="#C6C6C6" noshade align="center" size="1">";
}
?>
<?
$Read=mysql_fetch_array($Read_query);
}
}
mysql_close($Connect);
?>
<br></small>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="50%">
<? if (intval(($ResultsPerPage*($OnPage-1))+$ResultsPerPage)>intval($HTTP_GET_VARSї"results"]))
{
?>
<b>Displaying Results: </b><? echo ($ResultsPerPage*($OnPage-1))+1; ?> - <? echo $HTTP_GET_VARSї"results"]; ?> of <? echo $HTTP_GET_VARSї"results"]; ?>
<? }
else
{
?>
<b>Displaying Results: </b><? echo ($ResultsPerPage*($OnPage-1))+1; ?> - <? echo ($ResultsPerPage*($OnPage-1))+$ResultsPerPage; ?> of <? echo $HTTP_GET_VARSї"results"]; ?>
<? } ?>
</td>
<td width="50%" align="right">
<b>Result Page: </b>
<?
if (intval($TotalResults/$ResultsPerPage)==$TotalResults/$ResultsPerPage)
{
$TotalPages=intval($TotalResults/$ResultsPerPage);
}
else
{
$TotalPages=intval($TotalResults/$ResultsPerPage)+1;
}
$LoopNum=0;
while(!($LoopNum==$TotalPages))
{
$LoopNum=$LoopNum+1;
if ($LoopNum==$TotalPages)
{
print "<a href="/search.php?view=browse&string=".rawurlencode($SearchString)."&results=".$HTTP_GET_VARSї"results"]."§ion=articles&page=".$LoopNum."">".$LoopNum."</a>";
}
else
{
print "<a href="/search.php?view=browse&string=".rawurlencode($SearchString)."&results=".$HTTP_GET_VARSї"results"]."§ion=articles&page=".$LoopNum."">".$LoopNum."</a> ";
}
}
?>
</td>
</tr>
</table>
<?
return $function_ret;
}
?><!--#include file="./db_data/ssi_data/footer.php"-->
Posted: Thu Feb 13, 2003 7:07 pm
by Splitfyre
anyone?
Posted: Thu Feb 13, 2003 11:50 pm
by aybra
is line 158 near the bottom of the script? like one of the last lines?
Posted: Fri Feb 14, 2003 2:29 am
by twigletmac
First of all which version of PHP are you using?
Secondly, did you read what BigE said? $GLOBALS (if it exists) would be a massive array, not sure why you'd want to extract() that - sorry I was not paying attention to exactly what you were trying to do when I first answered

.
Thirdly, you don't need a closing bracket after the global bit because that isn't the end of the function, you only need a closing bracket once all of the code for the function has been written.
Finally, for more info:
http://www.php.net/phpversion
http://www.php.net/manual/en/reserved.v ... es.globals
http://www.php.net/manual/en/language.v ... efined.php
Mac
Helllp! :-)
Posted: Fri Feb 14, 2003 6:16 pm
by Splitfyre
Good Afternoon Guys,
Well I got the frickin page to load.. now it just won't search on anything. PHP has been a bit of a challenge (but in a sense, its good).
Here's the page:
http://www.futurelooks.com/search.php?view=results
But if I search on anything it gives me this error:
Warning: Supplied argument is not a valid MySQL result resource in /home/virtual/site3/fst/var/www/html/search.php on line 60
This is line 60:
Code: Select all
$Read=mysql_fetch_array($Read_query);
I think this might be due to the fact that I don't use the extract function..
i.e.
Code: Select all
function ViewForm()
{
global $GLOBALS;
}
Helllp!

Posted: Fri Feb 14, 2003 10:08 pm
by aybra
Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /home/virtual/site3/fst/var/www/html/search.php on line 30
is all i get