| | |
why my db query gets "stuck" when I manually test url with a '
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2007
Posts: 63
Reputation:
Solved Threads: 0
Hello, all:
I'm trying to sanitize/secure my query, and it all seems ok when I test it with most special-characters... but when I try to test the single quote (') like this... www.mysite.com/page.php?category='
Then it gives me this error:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''''' at line 1"
It seems to do it only when I test it on the category variable... it only does it with single quotes, it's Ok with double quotes; so I dont get it...
So if I test it with the other variables like this...
http://www.sitetemplates101.com/work...tegory=1&type='
http://www.sitetemplates101.com/work...type=2&filter='
Then it works fine, it simply refreshes or disregards entry...
See here below the code-snippet i have... what am I doing wrong???
Thanks!!
PS. Forgot to mention I have .htaccess to have magic-quotes OFF
<CODE>
// THESE ARE VARIABLES
$colname1_worksRS = "-1";
$colname2_worksRS = "-1";
$colname3_worksRS = "-1";
if (isset($_GET['category'])) {
$colname1_worksRS = mysql_real_escape_string($_GET['category']);}
if (isset($_GET['type'])) {
$colname2_worksRS = mysql_real_escape_string($_GET['type']);}
if (isset($_GET['filter'])) {
$colname3_worksRS = mysql_real_escape_string($_GET['filter']);}
// THIS IS COMPOUND SELECT STATEMENT ACCORDING TO CALLED VARIABLES
$query_worksRS = "SELECT * FROM works";
if (!empty($_GET['category']))
{
$query_worksRS .= " WHERE Type = '$colname1_worksRS'";
}
if (!empty($_GET['type']))
{
$query_worksRS .= " AND Subject = '$colname2_worksRS'";
}
if ((!empty($_GET['filter'])) && $_GET['filter'] == 'Price')
{
$query_worksRS .= " ORDER BY Price DESC";
}
elseif ($_GET['filter'] == 'Size')
{
$query_worksRS .= " ORDER BY Size DESC";
}else {
$query_worksRS .= " ORDER BY ProductID DESC";
}
</CODE>
I'm trying to sanitize/secure my query, and it all seems ok when I test it with most special-characters... but when I try to test the single quote (') like this... www.mysite.com/page.php?category='
Then it gives me this error:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''''' at line 1"
It seems to do it only when I test it on the category variable... it only does it with single quotes, it's Ok with double quotes; so I dont get it...
So if I test it with the other variables like this...
http://www.sitetemplates101.com/work...tegory=1&type='
http://www.sitetemplates101.com/work...type=2&filter='
Then it works fine, it simply refreshes or disregards entry...
See here below the code-snippet i have... what am I doing wrong???
Thanks!!
PS. Forgot to mention I have .htaccess to have magic-quotes OFF
<CODE>
// THESE ARE VARIABLES
$colname1_worksRS = "-1";
$colname2_worksRS = "-1";
$colname3_worksRS = "-1";
if (isset($_GET['category'])) {
$colname1_worksRS = mysql_real_escape_string($_GET['category']);}
if (isset($_GET['type'])) {
$colname2_worksRS = mysql_real_escape_string($_GET['type']);}
if (isset($_GET['filter'])) {
$colname3_worksRS = mysql_real_escape_string($_GET['filter']);}
// THIS IS COMPOUND SELECT STATEMENT ACCORDING TO CALLED VARIABLES
$query_worksRS = "SELECT * FROM works";
if (!empty($_GET['category']))
{
$query_worksRS .= " WHERE Type = '$colname1_worksRS'";
}
if (!empty($_GET['type']))
{
$query_worksRS .= " AND Subject = '$colname2_worksRS'";
}
if ((!empty($_GET['filter'])) && $_GET['filter'] == 'Price')
{
$query_worksRS .= " ORDER BY Price DESC";
}
elseif ($_GET['filter'] == 'Size')
{
$query_worksRS .= " ORDER BY Size DESC";
}else {
$query_worksRS .= " ORDER BY ProductID DESC";
}
</CODE>
![]() |
Similar Threads
- Comment form not appearing??? (JavaScript / DHTML / AJAX)
- Spry Menu Borders and "Blank" buttons for column width matching - please help! (HTML and CSS)
- What does this expression means "$this->$sometexe()"? (PHP)
- "Windows XP Security Message" Stuck to my background, won't go away! (Viruses, Spyware and other Nasties)
- vista to xp "upgrade" (Windows NT / 2000 / XP)
- Firefox Compatibility help with script (JavaScript / DHTML / AJAX)
- PHP how to send results from one query to another php script (PHP)
- Need update query--Remove the coma "," (PHP)
- Error while trying the update query (ASP)
- google "keyword" question (Search Engine Optimization)
Other Threads in the PHP Forum
Views: 208 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class clean cms code countingeverycharactersfromastring cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail match menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions simple sms soap source space spam speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





