Re: [PHP] Dreaded expecting `T_VARIABLE' or... Error -- long post
the line global ; should be global $some_variable; or delete it Verdon Vaillancourt wrote: >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 = ""; > >$box_stuff .= "Search hints can go >here"; > >$box_stuff .= " > > > >Search for: > >Companyalign=\"left\">Categoryalign=\"left\">City > >align=\"left\" valign=\"top\"> > >\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 .= "$c2[cattext] ( >$num_type)"; > >} > >} > >$box_stuff .= " > > > > > > > >\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 .= "$c3[city] ($num >_type3)"; > >} > >} > >$box_stuff .= "\n"; > > > >$box_stuff .= " > >value=\"Search\"> Note: searching for all can produce a large >page! > > > >"; > > > >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 .= "$c2[cattext] ( >$num_type)"; > >} //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 = ""; > >$box_stuff .= ""; > >if ($r
RE: [PHP] Dreaded expecting `T_VARIABLE' or... Error -- long post
If you're going to use an array in a string, you have to surround it with braces. echo "value is {$c2[something]} okay?"; Or, exit out of the string: echo "value is " . $c2['something'] . " okay?"; If you use it outside of the string, you need the single/double quotes around the key so you don't get an undefined constant warning. That looks like your problem. ---John Holmes... > -Original Message- > From: Verdon Vaillancourt [mailto:[EMAIL PROTECTED]] > Sent: Friday, October 11, 2002 12:34 PM > To: PHP-General > Subject: [PHP] Dreaded expecting `T_VARIABLE' or... Error -- long post > > 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 = ""; > > $box_stuff .= "Search hints can go > here"; > > $box_stuff .= " > > > > Search for: > > Company align=\"left\">Category align=\"left\">City > > align=\"left\" valign=\"top\"> > > \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 .= "$c2[cattex t] > ( > $num_type)"; > > } > > } > > $box_stuff .= " > > > > > > > > \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 .= "$c3[city] ( $n > um > _type3)"; > > } > > } > > $box_stuff .= "\n"; > > > > $box_stuff .= " > > value=\"Search\"> Note: searching for all can produce a large > page! > > > > "; > > > > 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 .= "$c2[cattex t] > ( > $num_type)"; > > } //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 alon