Hi Apologies if this question has been answered before and I can't find it.
I have searched and although finding similar issues, I haven't been able to
fix. 

I have a file that creates a search for and then is supposed to post to
itself to retriev results. When I add the first function (the search form)
everything seems OK. The page renders, the select menus are populated from
my mySQL db. 

When I add the second function (the results). I start getting an error that
refers to a line number in my initial function that was previously OK. I
gather the error has something to do with syntax, but I can't find it.

I'll show some examples and then detail the error.

My intial code that creates the search form and works is:


PHP:
------------------------------------------------------------------------


// Handles session initialization

include("open_session.php");

if(!isset($mainfile))

{
  include("mainfile.php");
}

// Global configuration data
include("config.php");

// Generates page header
include ("header.php");

function sform() {

include("config.php");

$box_title = "Search Form";

$box_stuff = "<table width=\"100%\"><tr><td align=\"left\">";

$box_stuff .= "<span class=\"finePrint\">Search hints can go
here</span></td></tr></table>";

$box_stuff .= "

<center><form action=\"./search_users.php\" method=\"post\">

<table><tr><td colspan=3 align=\"left\"><h4>Search for:</h4></td></tr>

<tr><td align=\"left\"><font size=\"-1\">Company</font></td><td
align=\"left\"><font size=\"-1\">Category</font></td><td
align=\"left\"><font size=\"-1\">City</font></td></tr>

<tr><td align=\"left\" valign=\"top\"><input name=\"company\"></td><td
align=\"left\" valign=\"top\">

<select name=\"cat\" size=\"7\" multiple>\n";


$cat_result = mysql_query("select cat, catkey, cattext, count(cat) AS
num_type FROM " . $table_prefix."users LEFT JOIN
" . $table_prefix."users_cat ON cat=catkey GROUP BY cattext ORDER BY
cattext");

$categories = mysql_fetch_array($cat_result);

if ($categories) {

    while ($c2 = mysql_fetch_array($cat_result)) {

    $num_type = $c2[num_type];

    $box_stuff .= "<option name=\"cat\" value=\"$c2[catkey]\">$c2[cattext] (
$num_type)</option>";

    }

}

$box_stuff .= "

</select>

</td>

<td align=\"left\" valign=\"top\">

<select name=\"city\" size=\"7\" multiple>\n";



$city_result = mysql_query("select city, count(city) AS num_type FROM
" . $table_prefix."users GROUP BY city ORDER BY city");

$cities = mysql_fetch_array($city_result);

if ($cities) {

    while ($c3 = mysql_fetch_array($city_result)) {

    $num_type3 = $c3[num_type];

    $box_stuff .= "<option name=\"city\" value=\"$c3[city]\">$c3[city] ($num
_type3)</option>";

    }

}

$box_stuff .= "</select></td></tr>\n";



$box_stuff .= "

<tr><td align=\"left\" colspan=3 align=\"center\"><input type=\"submit\"
value=\"Search\"> Note: searching for all can produce a large
page!</td></tr>

</table><input type=\"hidden\" name=\"op\" value=\"search\" />

</form></center>";



thememainbox($box_title, $box_stuff);

include("footer.php");

}



switch($op) {

    case "search":

        search();

        break;



    default:

        sform();

        break;

  }



------------------------------------------------------------------------


Now, when I add anything for the function search() , even a simple message
printed to the page such as:


PHP:
------------------------------------------------------------------------


function search()

{

    include('config.php');

    global ;

    $box_title = "Search Results";

    $box_stuff .= "Results here";

    thememainbox($box_title, $box_stuff);

    include("footer.php");

}


------------------------------------------------------------------------


I get the error: Parse error: parse error, expecting `T_VARIABLE' or `'$''
in /Library/WebServer/Documents/phpwebsite/search_users.php on line 45

BTW... line 45 is part of the initial funtion that was working before:


PHP:
------------------------------------------------------------------------

$cat_result = mysql_query("select cat, catkey, cattext, count(cat) AS
num_type FROM " . $table_prefix."users LEFT JOIN
" . $table_prefix."users_cat ON cat=catkey GROUP BY cattext ORDER BY
cattext");

$categories = mysql_fetch_array($cat_result);

if ($categories) {

    while ($c2 = mysql_fetch_array($cat_result)) {

    $num_type = $c2[num_type];

    $box_stuff .= "<option name=\"cat\" value=\"$c2[catkey]\">$c2[cattext] (
$num_type)</option>";

    }  //THIS IS LINE 45

}

------------------------------------------------------------------------


I feel that if I can get past this, I can likely get my actual search to
work. If you're curious, the following code is what I actually have in mind
for the search function. I just can't get far enough along to even test it.
I would surely appreciate any advice that anyone can extend.:


PHP:
------------------------------------------------------------------------

function search() {

include("config.php");

global $company, $cat, $city, $catkey, $cattext, Order;

$box_title = "Search Results";

if ($cat>0) {

    $classreq="AND catkey=$cat";

    }

  if (!$Order) {

    $Order="company";

    }

$query = "SELECT company, city, cat, catkey, cattext FROM
" . $table_prefix."users LEFT JOIN
" . $table_prefix."users_cat ON cat=catkey WHERE company LIKE '%$company%' A
ND city LIKE '%$city%' AND cat LIKE '%$cat%' $classreq ORDER BY $Order";

$result = mysql_query($query);


$box_stuff = "<center><br>";

$box_stuff .= "<table cellpadding=1 border=0 cellspacing=0 width=\"100%\">";

if ($result){

    if ($r = mysql_fetch_array($result)){

        do {

        $box_stuff .="

<tr class=\"type5\"><td align=\"left\">Company</td><td align=\"left\">Catego
ry</td><td align=\"left\">City</td></tr>

<tr class=\"type5\"><td align=\"left\">$r[company]</td><td align=\"left\">$r
[cattext]</td><td align=\"left\">$r[city]</td></tr>";

        } while ($r = mysql_fetch_array($result));

    } else {

        $box_stuff .= "<b>Search Failed</b>";

    }

}


$box_stuff .= "</center>";

thememainbox($box_title, $box_stuff);

include("footer.php");

}


------------------------------------------------------------------------


Thanks again, 
Verdon


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to