Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules
Author Message
thundarfoot
Regular
Regular



Joined: Jan 16, 2008
Posts: 75

PostPosted: Tue Feb 05, 2008 6:53 am Reply with quote

I have a problem with a script I am working on the script worked until I began trying to add pagination(via dreamweaver) now when I try to change page I get an error.

the error msg I get is...Got error 'empty (sub)expression' from regexp.

I have a drop down select form in a block whose value when submited gets stored as $name and used in a query via regexp..

basically the script outputs the first 10 results, but when I next page I get the error from the regexp value being empty..

here is the code I am working with, I really appreciate any advice on how to get this working.


Code:
<?php

if (!defined('MODULE_FILE')) die('You can\'t access this file directly...');
require_once('mainfile.php');
require_once('../LootWhore/Connections/LWC.php');
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
$pagetitle = '- You Module Name'; // If you need this to be multi-lingual then you will have to use language defines
include_once 'header.php'; 

$currentPage = $_SERVER["PHP_SELF"];
$maxRows_Cards = 10;
$pageNum_Cards = 0;
if (isset($_GET['pageNum_Cards'])) {
  $pageNum_Cards = $_GET['pageNum_Cards'];
}
$startRow_Cards = $pageNum_Cards * $maxRows_Cards;

$name = $_POST['select'];
mysql_select_db($database_LWC, $LWC);
$query_Cards = "SELECT Name, `Class`, Drops, Details FROM skill_cards WHERE skill_cards.`Class` REGEXP '$name' ORDER BY Name ASC";
$query_limit_Cards = sprintf("%s LIMIT %d, %d", $query_Cards, $startRow_Cards, $maxRows_Cards);
$Cards = mysql_query($query_limit_Cards, $LWC) or die(mysql_error());
$row_Cards = mysql_fetch_assoc($Cards);

if (isset($_GET['totalRows_Cards'])) {
  $totalRows_Cards = $_GET['totalRows_Cards'];
} else {
  $all_Cards = mysql_query($query_Cards);
  $totalRows_Cards = mysql_num_rows($all_Cards);
}
$totalPages_Cards = ceil($totalRows_Cards/$maxRows_Cards)-1;

$queryString_Cards = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Cards") == false &&
        stristr($param, "totalRows_Cards") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Cards = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Cards = sprintf("&totalRows_Cards=%d%s", $totalRows_Cards, $queryString_Cards);


// Cut a bunch of code here, for table format and display.

        <table border="0" width="50%" align="center">
          <tr>
            <td width="23%" align="center"><?php if ($pageNum_Cards > 0) { // Show if not first page ?>
                  <a href="<?php printf("%s?pageNum_Cards=%d%s", $currentPage, 0, $queryString_Cards); ?>"><img src="First.gif" border=0></a>
                  <?php } // Show if not first page ?>
            </td>
            <td width="31%" align="center"><?php if ($pageNum_Cards > 0) { // Show if not first page ?>
                  <a href="<?php printf("%s?pageNum_Cards=%d%s", $currentPage, max(0, $pageNum_Cards - 1), $queryString_Cards); ?>"><img src="Previous.gif" border=0></a>
                  <?php } // Show if not first page ?>
            </td>
            <td width="23%" align="center"><?php if ($pageNum_Cards < $totalPages_Cards) { // Show if not last page ?>
                  <a href="<?php printf("%s?pageNum_Cards=%d%s", $currentPage, min($totalPages_Cards, $pageNum_Cards + 1), $queryString_Cards); ?>"><img src="Next.gif" border=0></a>
                  <?php } // Show if not last page ?>
            </td>
            <td width="23%" align="center"><?php if ($pageNum_Cards < $totalPages_Cards) { // Show if not last page ?>
                  <a href="<?php printf("%s?pageNum_Cards=%d%s", $currentPage, $totalPages_Cards, $queryString_Cards); ?>"><img src="Last.gif" border=0></a>
                  <?php } // Show if not last page ?>
 
View user's profile Send private message
Gremmie
Former Moderator in Good Standing



Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Tue Feb 05, 2008 8:00 am Reply with quote

Hmmm...you are getting somethings out of $_GET and the $name out of $_POST. Could it be that on some invocations $name is empty because you didn't post anything?

And also you'll want to sanitize your user inputs before using them in SQL statements. At least run addslashes() on $name.

_________________
GCalendar - An Event Calendar for PHP-Nuke
Member_Map - A Google Maps Nuke Module 
View user's profile Send private message
thundarfoot







PostPosted: Tue Feb 05, 2008 3:53 pm Reply with quote

uhhh hmm...

I did post using the select form in the block but when I press a navigation button I lose the value that was previously selected in the form...if I remove pagination and put all records on one page then it works.

as for user input sanitaion I havent a clue.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©