Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Help with a PHP 5.3 error in faqdesk_show.php file


bibleman

Recommended Posts

Hi,

 

I am getting an error after updated to PHP 5.3 in my faqdesk_show.php file.

 

I have changed the first line of the following code:

 

 if ( (!$HTTP_GET_VARS['sort']) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'],0,1) > $cl_size) ) {
for ($col=0; $col<$cl_size; $col++) {
	if ($column_list[$col] == 'FAQDESK_QUESTION') {
		$HTTP_GET_VARS['sort'] = $col+1 . 'a';
		$listing_sql .= " order by p.faqdesk_date_added desc";
		break;
	}
} 

 

to this first line:

 

if ( (!$_GET['sort']) || (!preg_replace('/[1-8][ad]$/', $_GET['sort'])) || (substr($_GET['sort'],0,1) > $cl_size) ) {
for ($col=0; $col<$cl_size; $col++) {
	if ($column_list[$col] == 'FAQDESK_QUESTION') {
		$HTTP_GET_VARS['sort'] = $col+1 . 'a';
		$listing_sql .= " order by p.faqdesk_date_added desc";
		break;
	}
} 

 

It fixed one of my errors but now I am getting this error:

 

PHP Warning: preg_replace() expects at least 3 parameters, 2 given in /var/www/vhosts/mywebsite.com/httpdocs/includes/modules/faqdesk/faqdesk_show.php on line 59

 

Does anyone have any idea what I need to change to correct this error?

 

Thanks

I'm having a great Day - hope you are too!

 

Leon

Link to comment
Share on other sites

if ( (!$_GET['sort']) || (!preg_replace('/[1-8][ad]$/', '', $_GET['sort'])) || (substr($_GET['sort'],0,1) > $cl_size) ) {
       for ($col=0; $col<$cl_size; $col++) {
               if ($column_list[$col] == 'FAQDESK_QUESTION') {
                       $HTTP_GET_VARS['sort'] = $col+1 . 'a';
                       $listing_sql .= " order by p.faqdesk_date_added desc";
                       break;
               }
       } 

 

May work..

Link to comment
Share on other sites

ereg() would be replaced by preg_match(), not preg_replace(). Also, you added $ to the pattern (regular expression), which anchors the match to the end of the string rather than anywhere. Is that intentional?

Link to comment
Share on other sites

Missed that, good catch Phil.

 

if ( (!$_GET['sort']) || (!preg_match('/[1-8][ad]/', $_GET['sort'])) || (substr($_GET['sort'],0,1) > $cl_size) ) {
       for ($col=0; $col<$cl_size; $col++) {
               if ($column_list[$col] == 'FAQDESK_QUESTION') {
                       $HTTP_GET_VARS['sort'] = $col+1 . 'a';
                       $listing_sql .= " order by p.faqdesk_date_added desc";
                       break;
               }
       } 

Link to comment
Share on other sites

THANKS GUYS!

 

I replaced:

 

if ( (!$_GET['sort']) || (!preg_replace('/[1-8][ad]$/', '', $_GET['sort'])) || (substr($_GET['sort'],0,1) > $cl_size) ) {

 

with:

if ( (!$_GET['sort']) || (!preg_match('/[1-8][ad]/', $_GET['sort'])) || (substr($_GET['sort'],0,1) > $cl_size) ) {

 

It works great with no errors!

 

I do understand that since we changed ereg() from preg_replace() to preg_match() it no longer needs the ' '

 

Is that correct?

I'm having a great Day - hope you are too!

 

Leon

Link to comment
Share on other sites

Leon yes, that is correct I kept looking at the php and didn't notice the function was actually wrong.

 

preg_replace is a replace x with y in z function (3 parameters)

preg_match is search for x in y (2 parameters)

 

My suggestion on adding the , ' ' was only to pass a null parameter to stop the error. Phil, as usual nailed the problem which was we were looking at the wrong function to begin with.

Link to comment
Share on other sites

THANKS Guys.

 

I hope you know how much you are appreciated by those of us who know html but yet lack greatly in PHP coding.

 

You solved my problem.

I'm having a great Day - hope you are too!

 

Leon

Link to comment
Share on other sites

Phil, as usual nailed the problem which was we were looking at the wrong function to begin with.

 

Do you want to know how many times I hit my thumb with the hammer? On second thought...

Link to comment
Share on other sites

  • 1 month later...

NOW... in the same contribution I have another error.

 

In the faqdesk .php file I am getting this error.

 

PHP Warning: in_array() expects parameter 2 to be array, string given in /var/www/vhosts/mystore.com/httpdocs/includes/boxes/faqdesk.php on line 85

 


if ($foo_faqdesk[$counter]['parent'] == 0) {
   $faqPath_new = 'faqPath=' . $counter;
} else {
   $faqPath_new = 'faqPath=' . $foo_faqdesk[$counter]['path'];
}

$categories_faqdesk_string .= tep_href_link(FILENAME_FAQDESK_INDEX, $faqPath_new);
$categories_faqdesk_string .= '">';

if ( ($id) && (in_array($counter, $id)) ) {
   $categories_faqdesk_string .= '<b>';
}

 

Line 85 is:

 

if ( ($id) && (in_array($counter, $id)) ) {

 

Got any idea what I need to do to fix this?

 

Thanks

 

Leon

I'm having a great Day - hope you are too!

 

Leon

Link to comment
Share on other sites

You're going to have to look back up through the code to see where $id was last set before being used in line 85. Was there some other code change (add-on or manual edit) that might have accidentally repurposed $id? Or was $id originally a string for some other purpose, and someone/something removed the repurposing of it to an array? In either case, this shows the great weakness of untyped or weakly typed languages

Link to comment
Share on other sites

You're going to have to look back up through the code to see where $id was last set before being used in line 85. Was there some other code change (add-on or manual edit) that might have accidentally repurposed $id? Or was $id originally a string for some other purpose, and someone/something removed the repurposing of it to an array? In either case, this shows the great weakness of untyped or weakly typed languages

 

Thanks for responding Phil,

 

The only time the $id is used prior to line 85 is on line 68.

 

 

// -------------------------------------------------------------------------------------------------------------------------------------------------------------
function FAQDesk_show_category($counter) {
// -------------------------------------------------------------------------------------------------------------------------------------------------------------
(line 68) global $foo_faqdesk, $categories_faqdesk_string, $id;

for ($a=0; $a<$foo_faqdesk[$counter]['level']; $a++) {
$categories_faqdesk_string .= "  ";
}

$categories_faqdesk_string .= '<a href="';

if ($foo_faqdesk[$counter]['parent'] == 0) {
$faqPath_new = 'faqPath=' . $counter;
} else {
$faqPath_new = 'faqPath=' . $foo_faqdesk[$counter]['path'];
}

$categories_faqdesk_string .= tep_href_link(FILENAME_FAQDESK_INDEX, $faqPath_new);
$categories_faqdesk_string .= '">';

if ( ($id) && (in_array($counter, $id)) ) {
$categories_faqdesk_string .= '<b>';
}

 

Then you see it again beginning on line 168


//------------------------
if ($faqPath) {
$new_path = '';
//	$id = split('_', $faqPath);
(line 168)    $id = preg_split('/_/', $faqPath);

reset($id);
while (list($key, $value) = each($id)) {
	unset($prev_id);
	unset($first_id);

	$categories_faqdesk_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_FAQDESK_CATEGORIES . " c, "
	. TABLE_FAQDESK_CATEGORIES_DESCRIPTION . " cd where c.catagory_status = '1' and c.parent_id = '" . $value . "'
	and c.categories_id = cd.categories_id and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_name");

	$category_faqdesk_check = tep_db_num_rows($categories_faqdesk_query);
	if ($category_faqdesk_check > 0) {
		$new_path .= $value;
		while ($row = tep_db_fetch_array($categories_faqdesk_query)) {
			$foo_faqdesk[$row['categories_id']] = array(
				'name' => $row['categories_name'],
				'parent' => $row['parent_id'],
				'level' => $key+1,
				'path' => $new_path . '_' . $row['categories_id'],
				'next_id' => false
			);

 

That's it for the whole file.

 

Thanks for helping,

Leon

I'm having a great Day - hope you are too!

 

Leon

Link to comment
Share on other sites

OK, line 68 says that $id is set somewhere outside of the function FAQDesk_show_category(). You're going to have to trace through other places in the file that set $id, and also confirm that somewhere in the file, $id is set (wasn't accidentally omitted). Presumably this worked at one time for the author -- have you asked them? Have there been any add-ons or custom editing to this file? Very importantly, was this add-on written for osC 2.2, and you're using it in 2.3.1? If so, it could be that in 2.2 $id was an array, and the standard value was used "as is" by the add-on. If in osC 2.3.1 it turned into a string, you would have to add code to turn the string into an array. That would depend on how $id is laid out. For example, if $id is now "1 2 3", you could add code:

$id_array = explode(' ', $id);

and replace downstream uses (in a function, after the global statement) of $id with $id_array. My guess is that you'll find something similar to that. I would not change $id itself, but would make a new variable, so you don't screw up standard osC 2.3.1 code.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...