PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Splitfyre
Forum Newbie
Posts: 9 Joined: Wed Feb 12, 2003 8:27 pm
Location: Vancouver
Contact:
Post
by Splitfyre » Wed Feb 12, 2003 8:27 pm
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.
redcircle
Forum Commoner
Posts: 43 Joined: Fri Jan 31, 2003 8:47 pm
Location: michigan, usa
Post
by redcircle » Wed Feb 12, 2003 8:44 pm
look for missplaced or missing { or } chars.
Splitfyre
Forum Newbie
Posts: 9 Joined: Wed Feb 12, 2003 8:27 pm
Location: Vancouver
Contact:
Post
by Splitfyre » Thu Feb 13, 2003 12:58 am
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
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Thu Feb 13, 2003 2:01 am
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
Splitfyre
Forum Newbie
Posts: 9 Joined: Wed Feb 12, 2003 8:27 pm
Location: Vancouver
Contact:
Post
by Splitfyre » Thu Feb 13, 2003 10:25 am
After applying that snippet of code the page won't load at all.
aybra
Forum Commoner
Posts: 56 Joined: Sun Nov 24, 2002 12:52 am
Post
by aybra » Thu Feb 13, 2003 10:28 am
did you add a closing }??
twigs dosnt have one..
Splitfyre
Forum Newbie
Posts: 9 Joined: Wed Feb 12, 2003 8:27 pm
Location: Vancouver
Contact:
Post
by Splitfyre » Thu Feb 13, 2003 11:03 am
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.
aybra
Forum Commoner
Posts: 56 Joined: Sun Nov 24, 2002 12:52 am
Post
by aybra » Thu Feb 13, 2003 11:14 am
put it at the end of the function.
I'm assuming yes, next line
Last edited by
aybra on Fri Feb 14, 2003 10:47 am, edited 1 time in total.
BigE
Site Admin
Posts: 139 Joined: Fri Apr 19, 2002 9:49 am
Location: Missouri, USA
Contact:
Post
by BigE » Thu Feb 13, 2003 11:23 am
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.
Splitfyre
Forum Newbie
Posts: 9 Joined: Wed Feb 12, 2003 8:27 pm
Location: Vancouver
Contact:
Post
by Splitfyre » Thu Feb 13, 2003 3:36 pm
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"-->
Splitfyre
Forum Newbie
Posts: 9 Joined: Wed Feb 12, 2003 8:27 pm
Location: Vancouver
Contact:
Post
by Splitfyre » Thu Feb 13, 2003 7:07 pm
anyone?
aybra
Forum Commoner
Posts: 56 Joined: Sun Nov 24, 2002 12:52 am
Post
by aybra » Thu Feb 13, 2003 11:50 pm
is line 158 near the bottom of the script? like one of the last lines?
Splitfyre
Forum Newbie
Posts: 9 Joined: Wed Feb 12, 2003 8:27 pm
Location: Vancouver
Contact:
Post
by Splitfyre » Fri Feb 14, 2003 6:16 pm
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!
aybra
Forum Commoner
Posts: 56 Joined: Sun Nov 24, 2002 12:52 am
Post
by aybra » Fri Feb 14, 2003 10:08 pm
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