php code with error

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

nicosns
Forum Newbie
Posts: 21
Joined: Thu Jun 21, 2007 1:53 pm

php code with error

Post by nicosns »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello

I found this code on the Sphider forum. It's about a question on how to remove [b]&search=1[/b] from the first search url. It sounds interesting, but the code that someone posted as a solution has an error!

There is a problem with [b]default:[/b] on line 132

[url]http://www.sphider.eu/forum/read.php?2,629[/url]

Code: Select all

<?php
/*******************************************
* Sphider Version 1.3.x
* This program is licensed under the GNU GPL.
* By Ando Saabas ando(a t)cs.ioc.ee
********************************************/
//error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
error_reporting(E_ALL);
$include_dir = "./include";
include ("$include_dir/commonfuncs.php");
//extract(getHttpVars());

if (isset($_GET['query']))
$query = $_GET['query'];
if (isset($_GET['search']))
$search = $_GET['search'];
if (isset($_GET['domain']))
$domain = $_GET['domain'];
if (isset($_GET['type']))
$type = $_GET['type'];
if (isset($_GET['catid']))
$catid = $_GET['catid'];
if (isset($_GET['category']))
$category = $_GET['category'];
if (isset($_GET['results']))
$results = $_GET['results'];
if (isset($_GET['start']))
$start = $_GET['start'];
if (isset($_GET['adv']))
$adv = $_GET['adv'];


$include_dir = "./include";
$template_dir = "./templates";
$settings_dir = "./settings";
$language_dir = "./languages";


require_once("$settings_dir/database.php");
require_once("$language_dir/en-language.php");
require_once("$include_dir/searchfuncs.php");
require_once("$include_dir/categoryfuncs.php");


include "$settings_dir/conf.php";

include "$template_dir/$template/header.html";
include "$language_dir/$language-language.php";


if (!isset($type)) {
$type = "and";
}

if (preg_match("/[^a-z0-9-.]+/", $domain)) {
$domain="";
}


if ($results != "") {
$results_per_page = $results;
}

if (get_magic_quotes_gpc()==1) {
$query = stripslashes($query);
}

if (!is_numeric($catid)) {
$catid = "";
}

if (!is_numeric($category)) {
$category = "";
}



if ($catid && is_numeric($catid)) {

$tpl_['category'] = sql_fetch_all('SELECT category FROM '.$mysql_table_prefix.'categories WHERE category_id='.(int)$_REQUEST['catid']);
}

$count_level0 = sql_fetch_all('SELECT count(*) FROM '.$mysql_table_prefix.'categories WHERE parent_num=0');
$has_categories = 0;

if ($count_level0) {
$has_categories = $count_level0[0][0];
}



require_once("$template_dir/$template/search_form.html");


function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}



function poweredby () {
global $sph_messages;
?>

<?php print $sph_messages['Powered by'];?> <a href="http://www.cs.ioc.ee/~ando/sphider/"><img src="sphider-logo.png" border="0" style="vertical-align: middle" alt="Sphider"></a>

<?php
}


function saveToLog ($query, $elapsed, $results) {
global $mysql_table_prefix;
if ($results =="") {
$results = 0;
}
$query = "insert into ".$mysql_table_prefix."query_log (query, time, elapsed, results) values ('$query', now(), '$elapsed', '$results')";
mysql_query($query);

echo mysql_error();

}



if (!isset($results)) {
$results = "";
}
$search_results = get_search_results($query, $start, $category, $type, $results, $domain);
require("$template_dir/$template/search_results.html");
break;
default:
if ($show_categories) {
if ($_REQUEST['catid'] && is_numeric($catid)) {
$cat_info = get_category_info($catid);
} else {
$cat_info = get_categories_view();
}
require("$template_dir/$template/categories.html");
}


include "$template_dir/$template/footer.html";
?>
Anyone can help to solve this 'small' problem? thx


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Remove it...? Can't you just ignore it instead?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

in search.php (original version) replace

Code: Select all

if (isset($_GET['query']))
	$query = $_GET['query'];
if (isset($_GET['search']))
	$search = $_GET['search'];
if (isset($_GET['domain'])) 
	$domain = $_GET['domain'];
by

Code: Select all

if (isset($_GET['query']))
	$query = $_GET['query'];
if (isset($_GET['search']))
	$search = $_GET['search'];
else if (isset($_GET['query']))
	$search = 1;
if (isset($_GET['domain'])) 
	$domain = $_GET['domain'];
in templates/standard/search_form.html remove the line

Code: Select all

<input type="hidden" name="search" value="1">
note: I'm unfamiliar with sphider (never used it) and don't know if this has any side-effects.
nicosns
Forum Newbie
Posts: 21
Joined: Thu Jun 21, 2007 1:53 pm

Post by nicosns »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Edit: @volka When I was writing this post I did not see yours yet...I'll try that now thx

When I use that code posted above, I get

Code: Select all

Parse error: syntax error, unexpected T_DEFAULT in /home/.... on line 132
I have then removed default: and uploade again. It gave me 2 error:
1. wrong file name, it must be header.php and not header.html...it's now ok
2. something with break;

Code: Select all

Fatal error: Cannot break/continue 1 level in /home/... on line 131
Last used code:

Code: Select all

<?php
/*******************************************
* Sphider Version 1.3.x
* This program is licensed under the GNU GPL.
* By Ando Saabas ando(a t)cs.ioc.ee
********************************************/
//error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
error_reporting(E_ALL);
$include_dir = "./include";
include ("$include_dir/commonfuncs.php");
//extract(getHttpVars());

if (isset($_GET['query']))
$query = $_GET['query'];
if (isset($_GET['search']))
$search = $_GET['search'];
if (isset($_GET['domain']))
$domain = $_GET['domain'];
if (isset($_GET['type']))
$type = $_GET['type'];
if (isset($_GET['catid']))
$catid = $_GET['catid'];
if (isset($_GET['category']))
$category = $_GET['category'];
if (isset($_GET['results']))
$results = $_GET['results'];
if (isset($_GET['start']))
$start = $_GET['start'];
if (isset($_GET['adv']))
$adv = $_GET['adv'];


$include_dir = "./include";
$template_dir = "./templates";
$settings_dir = "./settings";
$language_dir = "./languages";


require_once("$settings_dir/database.php");
require_once("$language_dir/en-language.php");
require_once("$include_dir/searchfuncs.php");
require_once("$include_dir/categoryfuncs.php");


include "$settings_dir/conf.php";

include "$template_dir/$template/header.php";
include "$language_dir/$language-language.php";


if (!isset($type)) {
$type = "and";
}

if (preg_match("/[^a-z0-9-.]+/", $domain)) {
$domain="";
}


if ($results != "") {
$results_per_page = $results;
}

if (get_magic_quotes_gpc()==1) {
$query = stripslashes($query);
}

if (!is_numeric($catid)) {
$catid = "";
}

if (!is_numeric($category)) {
$category = "";
}



if ($catid && is_numeric($catid)) {

$tpl_['category'] = sql_fetch_all('SELECT category FROM '.$mysql_table_prefix.'categories WHERE category_id='.(int)$_REQUEST['catid']);
}

$count_level0 = sql_fetch_all('SELECT count(*) FROM '.$mysql_table_prefix.'categories WHERE parent_num=0');
$has_categories = 0;

if ($count_level0) {
$has_categories = $count_level0[0][0];
}



require_once("$template_dir/$template/search_form.html");


function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}



function poweredby () {
global $sph_messages;
?>

<?php print $sph_messages['Powered by'];?> <a href="http://www.cs.ioc.ee/~ando/sphider/"><img src="sphider-logo.png" border="0" style="vertical-align: middle" alt="Sphider"></a>

<?php
}


function saveToLog ($query, $elapsed, $results) {
global $mysql_table_prefix;
if ($results =="") {
$results = 0;
}
$query = "insert into ".$mysql_table_prefix."query_log (query, time, elapsed, results) values ('$query', now(), '$elapsed', '$results')";
mysql_query($query);

echo mysql_error();

}



if (!isset($results)) {
$results = "";
}
$search_results = get_search_results($query, $start, $category, $type, $results, $domain);
require("$template_dir/$template/search_results.html");
break;
if ($show_categories) {
if ($_REQUEST['catid'] && is_numeric($catid)) {
$cat_info = get_category_info($catid);
} else {
$cat_info = get_categories_view();
}
require("$template_dir/$template/categories.html");
}


include "$template_dir/$template/footer.html";
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
nicosns
Forum Newbie
Posts: 21
Joined: Thu Jun 21, 2007 1:53 pm

Post by nicosns »

volka wrote:in search.php (original version) replace

Code: Select all

if (isset($_GET['query']))
	$query = $_GET['query'];
if (isset($_GET['search']))
	$search = $_GET['search'];
if (isset($_GET['domain'])) 
	$domain = $_GET['domain'];
by

Code: Select all

if (isset($_GET['query']))
	$query = $_GET['query'];
if (isset($_GET['search']))
	$search = $_GET['search'];
else if (isset($_GET['query']))
	$search = 1;
if (isset($_GET['domain'])) 
	$domain = $_GET['domain'];
in templates/standard/search_form.html remove the line

Code: Select all

<input type="hidden" name="search" value="1">
note: I'm unfamiliar with sphider (never used it) and don't know if this has any side-effects.
The error is:

Code: Select all

Parse error: syntax error, unexpected T_DEFAULT in /home/... on line 134
line 134 is default:

I have then removed default:. Result after showing a part of the page correctly

Code: Select all

Fatal error: Cannot break/continue 1 level in /home/... on line 133
line 133 is break;

removed that line also...Now there is no error, but also no search result.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

volka wrote:in search.php (original version) replace

Code: Select all

if (isset($_GET['query']))[/quote]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Can you help us by pointing out line 130 to 140 please?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

No need to. Please just use the original file version not the crippled version from the forum.
nicosns
Forum Newbie
Posts: 21
Joined: Thu Jun 21, 2007 1:53 pm

Post by nicosns »

thx! :D now it's working!

By the way I also removed default: and break;
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

nicosns wrote:By the way I also removed default: and break;
:?:
Yeah, why not removing the first 3 lines as well? Or line 17?
Last edited by volka on Thu Jun 21, 2007 5:14 pm, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I think properly tabbed code would have helped that out a little bit to. default and break are typically associated with switch statements (though break can be used to break out of other control structures).
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

I've never seen volka so ignored before. 8O
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Yes, and there is a switch statement in the original code. And it's good there.
Please, just take the original file, the file you got from the sphider archive, got the the code you got from the forum, the original code and add those two line.
Nothing more, nothing less.
Please do it.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

superdezign wrote:I've never seen volka so ignored before. 8O
Yes, and it's real bothersome.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

superdezign wrote:I've never seen volka so ignored before. 8O
I have, and it wasn't pretty. I suppose I should sit back and watch where this goes from here then...
Post Reply