Search is Broken! :(

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

Post Reply
Splitfyre
Forum Newbie
Posts: 9
Joined: Wed Feb 12, 2003 8:27 pm
Location: Vancouver
Contact:

Search is Broken! :(

Post 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.
User avatar
redcircle
Forum Commoner
Posts: 43
Joined: Fri Jan 31, 2003 8:47 pm
Location: michigan, usa

Post by redcircle »

look for missplaced or missing { or } chars.
Splitfyre
Forum Newbie
Posts: 9
Joined: Wed Feb 12, 2003 8:27 pm
Location: Vancouver
Contact:

Parse error: parse error in /home/virtual/site3/fst/var/www/

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Splitfyre
Forum Newbie
Posts: 9
Joined: Wed Feb 12, 2003 8:27 pm
Location: Vancouver
Contact:

Post by Splitfyre »

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 »

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 »

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 »

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.
User avatar
BigE
Site Admin
Posts: 139
Joined: Fri Apr 19, 2002 9:49 am
Location: Missouri, USA
Contact:

Post 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.
Splitfyre
Forum Newbie
Posts: 9
Joined: Wed Feb 12, 2003 8:27 pm
Location: Vancouver
Contact:

Search Code

Post 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:

Code: Select all

}
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&#1111;"view"])
&#123;
  case "form":
ViewForm();
    break;
  case "results":
ViewForm();
    break;
  case "browse":
ViewBrowse();
    break;
  default:

ViewForm();
    break;
&#125; 

//------------------------------------------------------------------------------------------------
function ViewForm() 
&#123; 
    global $GLOBALS; 
    extract($GLOBALS);
&#125;
//------------------------------------------------------------------------------------------------
?>
<br><b>Advanced Search</b><form method="POST" action="/search.php?view=results">
Search For: <input type="text" size="25" name="string">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<input type="reset" name="reset" value="Reset" style="font-size: 10pt; font-family: Tahoma">&nbsp;<input type="submit" name="search" value="Search" style="font-size: 10pt; font-family: Tahoma">
</form>
<? 
  if ($HTTP_GET_VARS&#1111;"view"]=="results")
  &#123;


    $SearchString=$HTTP_POST_VARS&#1111;"string"];

    if ($SearchString=="")
    &#123;

    &#125;
      else
    &#123;

// $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))
      &#123;

        $ArticleResults=0;
      &#125;
        else
      &#123;

        $ArticleResults=0;
        while(!(($Read==0)))
        &#123;

          $ArticleResults=$ArticleResults+1;
          $Read=mysql_fetch_array($Read_query);

        &#125; 
      &#125; 

      
      mysql_close($Connect);
    &#125; 

?>
<br>
<?     if ($SearchString=="")
    &#123;
?>
<b>Search Error!</b>
<?     &#125;
      else
    &#123;
?>		
<b>Search Results: "<?       echo $SearchString; ?>"</b>
<?     &#125; ?>
<br>
<?     if ($SearchString=="")
    &#123;
?>
You must enter a search string.
<?     &#125;
      else
    &#123;
?>
<?       if ($ArticleResults==0)
      &#123;
?>
No results found matching the string "<?         echo $SearchString; ?>".
<?       &#125; ?>
<?       if ($ArticleResults!=0)
      &#123;
?>
<?         echo $ArticleResults; ?> result(s) found in Articles matching your string.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?       &#125; ?>
<?     &#125; ?>

<?     if ($SearchString=="")
    &#123;
?>
<?     &#125;
      else
    &#123;
?>
<?       if ($ArticleResults!=0)
      &#123;
?>
<a href="/search.php?view=browse&string=<?         echo rawurlencode($SearchString); ?>&results=<?         echo $ArticleResults; ?>&section=articles&page=1">Browse Results</a><br>
<?       &#125; ?>
<?     &#125; ?>

<? 
  &#125;
    else
  &#123;

  &#125; 

?>
<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;
&#125; 


//------------------------------------------------------------------------------------------------
function ViewBrowse()
&#123;
  global extract($GLOBALS);


//------------------------------------------------------------------------------------------------
  $SearchString=$HTTP_GET_VARS&#1111;"string"];
  $ResultsPerPage=10;
  $OnPage=intval($HTTP_GET_VARS&#1111;"page"]);
  $TotalResults=intval($HTTP_GET_VARS&#1111;"results"]);
?>
<br><b>Advanced Search</b><form method="POST" action="/search.php?view=results">
Search For: <input type="text" size="25" name="string">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<input type="reset" name="reset" value="Reset" style="font-size: 10pt; font-family: Tahoma">&nbsp;<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))
  &#123;

  &#125;
    else
  &#123;


    $LoopNum=0;
    while(!($LoopNum==$ResultsPerPage*($OnPage-1)))
    &#123;

      $Read=mysql_fetch_array($Read_query);

      $LoopNum=$LoopNum+1;
    &#125; 
    $LoopNum=0;
    while(!($LoopNum==$ResultsPerPage || ($Read==0)))
    &#123;

      $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&#1111;"Section"]." ".$Read&#1111;"Type"]; ?>: </small><b><?       echo $Read&#1111;"Title"]; ?> (Page <?       echo $Read&#1111;"PageNumber"]; ?> of <?       echo $Read&#1111;"PageTotal"]; ?>)</b><small> on <?       echo $Read&#1111;"Date"]; ?></small>
		</td>
</tr>
<tr>
		<td width="100%" style="padding: 5px">
		<?       echo $Read&#1111;"Description"]; ?>
		<br>
		<div align="right"><a href="/display.php?i=<?       echo $Read&#1111;"ID"]; ?>&p=<?       echo $Read&#1111;"PageNumber"]; ?>">Check It Out</a></div>
		</td>
</tr>
</table>
<small>
<? 
      if ($LoopNum!=$ResultsPerPage)
      &#123;

        print "<hr color="#C6C6C6" noshade align="center" size="1">";

      &#125; 

?>
<? 
      $Read=mysql_fetch_array($Read_query);

    &#125; 
  &#125; 

  
  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&#1111;"results"]))
  &#123;
?>
		<b>Displaying Results: </b><?     echo ($ResultsPerPage*($OnPage-1))+1; ?> - <?     echo $HTTP_GET_VARS&#1111;"results"]; ?> of <?     echo $HTTP_GET_VARS&#1111;"results"]; ?>
<?   &#125;
    else
  &#123;
?>
		<b>Displaying Results: </b><?     echo ($ResultsPerPage*($OnPage-1))+1; ?> - <?     echo ($ResultsPerPage*($OnPage-1))+$ResultsPerPage; ?> of <?     echo $HTTP_GET_VARS&#1111;"results"]; ?>
<?   &#125; ?>
		</td>
		<td width="50%" align="right">
		<b>Result Page: </b>
<? 
  if (intval($TotalResults/$ResultsPerPage)==$TotalResults/$ResultsPerPage)
  &#123;

    $TotalPages=intval($TotalResults/$ResultsPerPage);
  &#125;
    else
  &#123;

    $TotalPages=intval($TotalResults/$ResultsPerPage)+1;
  &#125; 


  $LoopNum=0;
  while(!($LoopNum==$TotalPages))
  &#123;

    $LoopNum=$LoopNum+1;
    if ($LoopNum==$TotalPages)
    &#123;

      print "<a href="/search.php?view=browse&string=".rawurlencode($SearchString)."&results=".$HTTP_GET_VARS&#1111;"results"]."&section=articles&page=".$LoopNum."">".$LoopNum."</a>";
    &#125;
      else
    &#123;

      print "<a href="/search.php?view=browse&string=".rawurlencode($SearchString)."&results=".$HTTP_GET_VARS&#1111;"results"]."&section=articles&page=".$LoopNum."">".$LoopNum."</a> ";
    &#125; 

  &#125; 
?>
		</td>
</tr>
</table>
<? 
  return $function_ret;
&#125; 
?><!--#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 »

anyone?
aybra
Forum Commoner
Posts: 56
Joined: Sun Nov 24, 2002 12:52 am

Post by aybra »

is line 158 near the bottom of the script? like one of the last lines?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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 :oops: .

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
Splitfyre
Forum Newbie
Posts: 9
Joined: Wed Feb 12, 2003 8:27 pm
Location: Vancouver
Contact:

Helllp! :-)

Post 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() 
&#123; 
    global $GLOBALS; 
&#125;
Helllp! :?
aybra
Forum Commoner
Posts: 56
Joined: Sun Nov 24, 2002 12:52 am

Post 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
Post Reply