473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Passing MySQL Wildcard into URL

I have a search feature where users can search a database. All works
very well except for one small annoying bug.

If a user searches for anything using wildcards and the '%' is the
FIRST character searched for, my pagination routine doesn't pass the
correct value.

Say the user enters %300. The page displays the correct data for the
first page, indicates that it is page 1 of 11 and when the NEXT link is
clicked, the value changes to 00. I haven't figured out why the %3
drops, however I suspect it may be my use of quotes. Particular code is
below. Can anyone help me?

Platform is Apache on FC3, MySQL and PHP. Browser being used doesn't
matter.

<?
if($pageno == 1) {
echo "<TD CLASS=upperLinks>FIRST&nbsp;</TD><TD
CLASS=upperLinks>PREV&nbsp;</TD>";
echo "<TD CLASS=data1>FIRST&nbsp;</TD><TD CLASS=data1>PREV&nbsp;</TD>";
} else {
echo "<TD CLASS=data1> <A
HREF='{$_SERVER['PHP_SELF']}?pageno=1&searchfor=$searchfor&searchtype=$search type'
CLASS=upperLinks>FIRST</A></TD>";
$prevpage = $pageno - 1;
echo "<TD CLASS=data1> <A
HREF='{$_SERVER['PHP_SELF']}?pageno=$prevpage&searchfor=$searchfor&searchtype =$searchtype'
CLASS=upperLinks>PREV</A></TD>";
}
?>
<TD CLASS=data1>(Page <?=$pageno?> of <?=$lastpage?>)&nbsp;</TD>
<?
if ($pageno == $lastpage) {
echo "<TD CLASS=data1>NEXT&nbsp;</TD><TD CLASS=data1>LAST&nbsp;</TD>";
} else {
$nextpage = $pageno + 1;
echo "<TD CLASS=data1> <A
HREF='{$_SERVER['PHP_SELF']}?pageno=$nextpage&searchfor=$searchfor&searchtype =$searchtype'
CLASS=upperLinks>NEXT</A></TD>";
echo "<TD CLASS=data1> <A
HREF='{$_SERVER['PHP_SELF']}?pageno=$lastpage&searchfor=$searchfor&searchtype =$searchtype'
CLASS=upperLinks>LAST</A></TD>";

Thanks

rk

Jul 17 '05 #1
5 2420
Try urlencode() for the $searchfor variable. The reason why this is
happening is that %300 is converted before your script get to use it
like if it was used by urldecode().

Jul 17 '05 #2
I'll try that. The weird thing is that if I echo the 'searchfor'
variable it contains the correct value:

$nextpage = $pageno + 1;
echo $searchfor;
echo "<TD CLASS=data1> <A
HREF='{$_SERVER['PHP_SELF']}?p*ageno=$nextpage&searchfor=$sea*rchfor&searchty pe=$searchtype'

CLASS=upperLinks>NEXT</A></TD>*";

Jul 17 '05 #3
I may be wrong, but I think the problem is that, in URLs, % is a scape
character. For example, if you want to reference a remote file with
spaces on it's name (like "foo file.zip"), in your URL you use %20
(like "foo%20file.zip"). So the browser is simply misunderstanding your
"%" character.

Yous should not pass it. You can for example parse the criteria entered
by the user instead, eliminate the "%" of the variable and add a new
parameter to the URL, a flag that indicates that this concrete search
will use "%" at the beginning of the criteria. Add it programatically
to your SQL query and there you go.
redneck_kiwi wrote:
I'll try that. The weird thing is that if I echo the 'searchfor'
variable it contains the correct value:

$nextpage = $pageno + 1;
echo $searchfor;
echo "<TD CLASS=data1> <A
HREF='{$_SERVER['PHP_SELF']}?p*ageno=$nextpage&searchfor=$sea*rchfor&searchty pe=$searchtype'
CLASS=upperLinks>NEXT</A></TD>*";


Jul 17 '05 #4
That's what I meant. He can eliminate the problem by using urlencode().
As he said the first page works, most likely cause the search parameter
is passed on by HTTP POST requests, that urlencodes and decodes
automaticly...

Jul 17 '05 #5
I used the code below to try and zero in on where the problem was:

$nextpage = $pageno + 1;
$link='baanparts.php?pageno='.$nextpage.'&searchfo r='.$searchfor.'&searchtype='.
$searchtype.'CLASS=upperlinks>NEXT</A></TD>';
echo '<TD CLASS=data1><A HREF='.$link;

The '%' is definately where the problem is. I then tried doing a
URLENCODE/URLDECODE with the same results. The browser sees the % as a
start to a special character. Guess I'll have to do a switch statement
and if the user enters a leading % then deal with it properly.

Thanks everyone.

rk

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Lord Asriel | last post by:
I'm a newbie in mysql and I've a question about user definition in Mysql. According to informations collected from manuals I believed that a user definition specifying host="%" on mysql server...
4
by: Jeff Silverman | last post by:
This may be old news, but it's kinda frustrating and I wonder if Something Can Be Done: mysql> grant all on *.* to 'jeff_dev@localhost' identified by 'my^son^daniel'; ERROR 1145: The host or...
16
by: MLH | last post by:
Using MS Access, I have attached to MySQL servers in other states and other countries on the other side of my router. But when I use the MySQL ODBC driver 3.51 to connect to a MySQL server on my...
4
by: js | last post by:
I have a stored procedure named "processInventory" like the following. Depending on the passed in parameters, I would like to add a WHERE clause for "select" action. For example, if any varchar...
3
by: Lyn | last post by:
Hi, I have a Search input form which collects from the user a person's name. I am using LIKE with a "%" suffix in the SQL so that the user does not have to type in the full name. When they hit...
3
by: pc | last post by:
hi everyone, I am trying to connect to a new mysql installation. I have given root permission to connect to all databases from anywhere; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY...
4
by: | last post by:
Hello... i have a table which contains a column named "ask" and a column named "per"... my think is that i want to search in "ask" and echo the data stored in "per" for this entry... How do i do...
11
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result =...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.