For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > April 2006 > C++ query with mySQL









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author C++ query with mySQL
Sara

2006-04-10, 3:55 am

I have been stuck here, SOS call:

Using CGI.pm, I have the script calling certain categories from mySQL table.

my $cat = $q->param('cat');
my $dbh -> prepare ("SELECT * FROM main WHERE CAT='$cat'");

Sample Categories('CAT') are given below:

PHP/Ad_Management/Classifieds
Perl_and_CGI/Ad_Management
C_and_C++/Ad_Management

etc.

Calling the categories starting with PHP and Perl didn't cause any issue, but when I called the Categories
starting with C_and_C++, nothing was shown because CGI.pm was removing the characters ++.

I replaced the All ++ in the mySQL database with ASCII ++, so now the categories are in the DB are:
C_and_C++/Ad_Management

And now when I am calling the script:
http://mysite.com/cgi-bin/index.cgi...+/Ad_Management

Since CGI.pm removing ++, so in script I did this:

my $cat =~ s/C_and_C/C_and_C++/gi;

It should have extracted the results from DB containing C_and_C++, BUT NO.

it's printing and calling cat within script as "C_and_C++ /Ad_Managment"

Putting an extra Space after +, so mySQL failed to deliver matching categories.

Why an extra white space? or anything more reasonable I can do to call cat with "C++" from mySQL.


TIA.






David Dorward

2006-04-10, 3:55 am

On Mon, 2006-04-10 at 10:02 +0500, Sara wrote:
> Calling the categories starting with PHP and Perl didn't cause any issue, but when I called the Categories
> starting with C_and_C++, nothing was shown because CGI.pm was removing the characters ++.


> I replaced the All ++ in the mySQL database with ASCII ++, so now the categories are in the DB are:
> C_and_C++/Ad_Management


The "+" character has no special meaning in HTML, so you don't need to
represent it with HTML entities unless it doesn't exist in the character
encoding you are using (which is unlikely).

> And now when I am calling the script:
> http://mysite.com/cgi-bin/index.cgi...+/Ad_Management


However, the "+" character _does_ have special meaning in URLs - it
represents a space character. You should URL encode the data you pull
from the database. The URI::Escape module can help with this.

--
David Dorward <http://dorward.me.uk/>
"Anybody remotely interesting is mad, in some way or another."
-- The Greatest Show in the Galaxy
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com